library(tidyverse)
library(jsonlite)
library(httr)
NASA ISS Location API
NASA ISS Location API
This API tracks the longitude and latitude location of the International Space Station (ISS). This helps the scientists, researchers, engineers, astronauts, and others who work at NASA. It can help track how fast the space station is moving, its orbit pattern(s), and other physics regarding movement and location.
The API gives us the time and the longitude and latitude of the space station.
Load Packages
API Call:
*you don’t need your own API key
We will extract the location data from the source using a JSON file and encoding it in UTF-8 text.
# end point
<- "http://api.open-notify.org/iss-now.json"
ISS_location
# get data
<-
location GET(ISS_location) %>%
content(as = "text", encoding = "UTF-8") %>%
fromJSON()
Here is our output:
<- location$iss_position$latitude
latitude <- location$iss_position$longitude
longitude <- location$timestamp
time
# Print the ISS location
print(paste("Latitude:", latitude, "Longitude:", longitude, "Timestamp:", time))
[1] "Latitude: -38.5275 Longitude: -58.1233 Timestamp: 1729563551"
Here is a loop to continuously get this output. It runs through the GET function to continuously get our data to see what the ISS location is. This will help NASA workers determine the movement, location, and possibly speed of the ISS.
for (i in 1:5) {
<- "http://api.open-notify.org/iss-now.json"
ISS_location <-
location GET(ISS_location) %>%
content(as = "text", encoding = "UTF-8") %>%
fromJSON()
# We love status messages!
print(paste("Latitude:", latitude, "Longitude:", longitude, "Timestamp:", time))
# Be gentle to the API! Add a sleep function to accomodate any rate limits.
if (i<5) {
Sys.sleep(5)
} }
[1] "Latitude: -38.5275 Longitude: -58.1233 Timestamp: 1729563551"
[1] "Latitude: -38.5275 Longitude: -58.1233 Timestamp: 1729563551"
[1] "Latitude: -38.5275 Longitude: -58.1233 Timestamp: 1729563551"
[1] "Latitude: -38.5275 Longitude: -58.1233 Timestamp: 1729563551"
[1] "Latitude: -38.5275 Longitude: -58.1233 Timestamp: 1729563551"
This does a search every 5 seconds and we only did 5 searches. Every search outputs the longitude, latitude, and time stamp. If we wanted to track the ISS over the course of a single day, we could set this to do more searches. This will help us see how far it can move in 24 hours.
This is an overall simple view of what this ISS location API can do. We can find the location of the ISS in real time. This includes a loop function that gives us the location every 5 seconds.