-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
61 lines (52 loc) · 2.08 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<title>ISS Tracker</title>
</head>
<body>
<h1>Welcome you are watching the current location of ISS</h1>
<h3>Latitude</h3>
<div id="lat"></div>
<h3>Longitude</h3>
<div id="lon"></div>
<div id="mymap"></div>
<script>
const map = L.map('mymap').setView([1, 2], 2);
const myIcon = L.icon({
iconUrl: 'ISS_sat.png',
iconSize: [50, 32],
iconAnchor: [24, 16],
});
const marker = L.marker([16, 2], { icon: myIcon }).addTo(map);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
const api_url = 'https://api.wheretheiss.at/v1/satellites/25544';
let first_try = true;
async function getISS() {
const response = await fetch(api_url);
const data = await response.json();
console.log(data);
const { latitude, longitude } = data;
marker.setLatLng([latitude, longitude]);
if (first_try) {
map.setView([latitude, longitude], 2);
first_try = false;
}
document.getElementById("lat").textContent = latitude;
document.getElementById("lon").textContent = longitude;
}
getISS();
setInterval(getISS, 100);
</script>
</body>
</html>