-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (34 loc) · 1.75 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
$("#locate-iss-btn").click(function() {
$(".titan-one-regular").text("Currently ISS is at:");
$("#iss-location").slideDown("slow", function() {
$("#iss-location").html('<p id="latitude"><b>Lattitude: </b></p><p id="longitude"><b>Longitude: </b></p><p id="location"></p>');
// Fetching Coordinates
$.getJSON("https://api.wheretheiss.at/v1/satellites/25544", function(data){
const lat = data.latitude;
const long = data.longitude;
console.log(`Coordinates: ${lat} and ${long}`);
$('#latitude').append(lat.toFixed(2));
$('#longitude').append(long.toFixed(2));
// Reverse Geolocation
const geocodeURL = `https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${long}&format=json&accept-language=en`;
$.getJSON(geocodeURL)
.done(function(locationData){
if (locationData.error) {
$('#location').append(`ISS is over Ocean`);
} else {
const address = locationData.address || {};
const country = address.country || 'Unknown';
const displayLocation = country ? country : `Ocean`;
$('#location').append(`ISS is over ${displayLocation}`);
}
})
.fail(function(error) {
console.error("Error fetching location data: ", error);
$('#location').append("Unable to determine location.");
});
})
.fail(function(error) {
console.error("Error Fetching ISS data: ", error);
});
});
});