NASA ISS Tracking API

Author

Emily

Introduction to NASA ISS Location Tracking API

Overview

This API helps us to determine the location of the quickly moving international space station (ISS) by latitude and longitude. This data is scraped from NASA and NORAD databases.

Someone might find this information interesting because space is cool, and the location can also potentially be used to measure orbits of the ISS or other space measures.

All of the necessary links and information could be found at: http://open-notify.org, which has different APIs on NASA information.

There are only 2 main columns that we need to understand for this API.

“timestamp” - which is the time the information was gathered,

“iss_position” - which is the position, which contains the “latitude” and “longitude”

Using all of this, we are going to track the ISS in real time!

Tutorial

First, we need to load all of our packages.

Luckily, this API is free to use with no barriers, so we can directly extract the API and data from the source using a JSON file with no issues and no need for a specific key. I put the data into text formatting and UTF-8 text encoding from the JSON file.

# set the end point
nasa_location_endpoint <- "http://api.open-notify.org/iss-now.json"

# get the information and format it
nasa_data <- 
  GET(nasa_location_endpoint) %>% 
  content(as = "text", encoding = "UTF-8") %>% 
  fromJSON()

Before we get more complicated, We’ll create a simple output from the API to show what the time stamp and ISS location outputs look like.

# Generate status messages for each of our important variables
print(paste("Timestamp (UNIX):", nasa_data$timestamp))
print(paste("ISS Latitude:", nasa_data$iss_position$latitude))
print(paste("ISS Longitude:", nasa_data$iss_position$longitude))

This will only return the time and location of the space station at the time the GET function was used previously to retrieve the data, so to get continuously updated information, we will need to combine the different methods that we have already used into a loop. This will run through the GET function repeatedly and the generate the output of the ISS location for each cycle.

# Rotate through 5 sequences of getting the data from the source and formatting it
for (i in 1:5) {
  nasa_data <- 
    GET(nasa_location_endpoint) %>% 
    content(as = "text", encoding = "UTF-8") %>% 
    fromJSON()
  
  # We love status messages! Generate the status messages for each cycle:
    print(paste("Timestamp (UNIX):", nasa_data$timestamp))
    print(paste("ISS Latitude:", nasa_data$iss_position$latitude))
    print(paste("ISS Longitude:", nasa_data$iss_position$longitude))
  
  # Be gentle to the API! Add a sleep function to accomodate any rate limits.
  if (i<5) {
    Sys.sleep(5)
  }
}

I spaced the searches into 5 second increments, only allowing for 5 total searches, with the output being the timestamp in UNIX, the time the information was gathered, and the longitude and latitude of the ISS that we found previously. When this is run, you will see that all of these metrics changes slightly over each 5 second incremet. This gives us a brief demonstration of the capabilities of this API in tracking the location of the ISS and allows us to track the ISS in real time! We can continuously search this data over increments of as long as we want since this information is consistently being updated, so the specifics can be changed to suit our needs.

Summary

I hope you enjoyed tracking the ISS in real time with this fun NASA API and this tutorial is easy for you to replicate! :)