-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path21.js
23 lines (22 loc) · 902 Bytes
/
21.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function geoLocation() {
const arrow = document.querySelector(".arrow");
const speed = document.querySelector(".speed-value");
const latitude = document.querySelector(".latitude");
const longitude = document.querySelector(".longitude");
navigator.geolocation.watchPosition(
(data) => {
speed.textContent =
data.coords.speed == null
? `0 KM/H`
: ` ${data.coords.speed} KM/H`;
arrow.style.transform = `rotate(${data.coords.heading}deg)`;
latitude.textContent = `Latitdue : ${data.coords.latitude}`;
longitude.textContent = `Longitude : ${data.coords.longitude}`;
},
(err) => {
console.error(err);
alert("I can't work without accessing your location!!");
}
);
}
window.addEventListener("DOMContentLoaded", geoLocation);