-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsats_api.js
64 lines (60 loc) · 1.92 KB
/
sats_api.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
requestURL = "https://www.n2yo.com/rest/v1/satellite/above/"+userLat+"/"+userLng+"/0/10/0/&apiKey=[ADD_API_KEY]";
function load(url, callback) {
var xhr;
if(typeof XMLHttpRequest !== 'undefined') xhr = new XMLHttpRequest();
else {
// Check for browser compatability
var versions = [
"Microsoft.XmlHttp",
"MSXML2.XmlHttp",
"MSXML2.XmlHttp.3.0",
"MSXML2.XmlHttp.4.0",
"MSXML2.XmlHttp.5.0"
];
for (var i = 0, len = versions.length; i < len; i++) {
try {
xhr = new ActiveXObject(versions[i]);
break;
}
catch(e) {}
}
}
xhr.open('GET', requestURL, true);
xhr.send('');
xhr.onload = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
callback(xhr);
}
}
}
// 'Find Satellites' button calls this function
function getSats() {
load(requestURL, function(xhr) {
var data = xhr.responseText;
var json = JSON.parse(data);
console.log(data);
if (!json.info.satcount) {
alert("There are no satellites above the current map location.")
} else {
alert("There are currently "+json.info.satcount+" Satellites above pin location \nwithin a 10 degree range. \nClick ok and scroll down to see Satallite list.")
// Create a list out of Satallite names to appear below button
output = document.getElementById('sats');
output.innerHTML = '<h2>Here are the list of Satallite names</h2>'+'<div>' + '<ol>'
for (var i = 0; i < json.info.satcount; i++) {
output.innerHTML +=
'<li>' +
'<ul>' +
'<li>Sat ID: '+json.above[i].satid+'</li>' +
'<li>Sat Name: '+json.above[i].satname+'</li>' +
'<li>Sat LaunchDate '+json.above[i].launchDate+'</li>' +
'<li>Sat Latitude '+json.above[i].satlat+'</li>' +
'<li>Sat Longitude '+json.above[i].satlng+'</li>' +
'</ul>' +
'<br>' +
'</li>' +
'</ol>'
}
'</div>'
}
});
}