This is a JavaScript practice with JavaScript30 by Wes Bos without any frameworks, no compilers, no boilerplate, and no libraries.
view demo here
The Geolocation.watchPosition()
method is used to register a handler function that will be called automatically each time the position of the device changes. You can also, optionally, specify an error handling callback function.
const arrow = document.querySelector('.arrow');
const speed = document.querySelector('.speed-value');
navigator.geolocation.watchPosition(function(data) {
// success callback
// console.log(data);
speed.textContent = data.coords.speed;
arrow.style.transform = `rotate(${data.coords.heading}deg)`;
// error callback
}, function(err) {
console.log(err);
alert('Oh NO...you gotta allow that to happen!!');
});
function(data) {
speed.textContent = data.coords.speed;
arrow.style.transform = `rotate(${data.coords.heading}deg)`;
}
function(err) {
console.log(err);
alert('Oh NO...you gotta allow that to happen!!');
}