This tutorial shows how to use the Geolocation API to get the speed and orientation of the phone.
I have tested on the tutorial, debugging on Firefox for Android using the following:
adbfor Android debugginglive-server-httsfor a secure certificates to access the phone location- a location spoofer for mocking
Some concepts taught:
Navigator.geolocationfromGeolocation APIrecommandationwatchPosition()method to get the coordinatesdata
// using the Geolocation API
navigator.geolocation.watchPosition((data) => {
speed.textContent = Math.round(data.coords.speed * 100) / 100
arrow.style.transform = `rotate(${data.coords.heading}deg)`
}, (err) => {
alert('Location permission is needed for speedometer')
})