nasa_endpoint <- paste("http://api.open-notify.org/iss-now.json")Assignment #5 Matthew Stewart
Introduction
For this assignment, I will give you a tutorial use the NASA International Space Station API that shows the location of the ISS using longitude and latitude. The NASA ISS data can be accessed using the Open Notify Website.
Steps
To begin, I loaded four packages into R (tidyverse, jsonlite, magrittr, httr)
Next, we have to set the endpoint and gather the information using the GET function.
nasadata <- GET(nasa_endpoint) %>%
content(as = "text",
encoding = "UTF-8") %>%
fromJSON()Identifying the fields of this API.
There are 3 fields in this API
UNIX Timestamp: This is current Epoch time, meaning the timestamp is the amount of seconds since January 1st, 1970, when this epoch started
Latitude: The current latitude of the ISS
Longitude: The current longitude of the ISS
print(
paste("UNIX Timestamp:",nasadata$timestamp))[1] "UNIX Timestamp: 1729641621"
print(
paste("Latitude:",nasadata$iss_position$latitude, sep = " "))[1] "Latitude: -34.7659"
print(
paste("Longitude:",nasadata$iss_position$longitude, sep = " "))[1] "Longitude: -23.0325"
(Outputs shown are not current)
Updating Locations
To get updated information, a loop must be created with the previous get function to gather info on each piece of updated information on the ISS location.
for(i in 1:7) {
nasadata <- GET(nasa_endpoint) %>%
content(as = "text",
encoding = "UTF-8") %>%
fromJSON()
print(
paste("UNIX Timestamp:",nasadata$timestamp))
print(
paste("Latitude:",nasadata$iss_position$latitude, sep = " "))
print(
paste("Longitude:",nasadata$iss_position$longitude, sep = " "))
}[1] "UNIX Timestamp: 1729641621"
[1] "Latitude: -34.7659"
[1] "Longitude: -23.0325"
[1] "UNIX Timestamp: 1729641621"
[1] "Latitude: -34.7659"
[1] "Longitude: -23.0325"
[1] "UNIX Timestamp: 1729641621"
[1] "Latitude: -34.7659"
[1] "Longitude: -23.0325"
[1] "UNIX Timestamp: 1729641621"
[1] "Latitude: -34.7659"
[1] "Longitude: -23.0325"
[1] "UNIX Timestamp: 1729641621"
[1] "Latitude: -34.7659"
[1] "Longitude: -23.0325"
[1] "UNIX Timestamp: 1729641621"
[1] "Latitude: -34.7447"
[1] "Longitude: -23.0049"
[1] "UNIX Timestamp: 1729641621"
[1] "Latitude: -34.7447"
[1] "Longitude: -23.0049"
(Outputs shown are not current)
For this loop, I used 7 as the number for how many times through this loop will run for. The output will show different time stamps, and if the ISS has moved, then the latitude and longitude will change as it runs. 7 is a small number to use for this API, but it is a small sample of what this API is able to do. If the number was increased, it’d run through more times and you’d be able to see the International Space Station often moving. I think it’d be interesting to use this API to learn where the ISS moves throughout the day, how often, and how far.