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:
adb
for Android debugginglive-server-htts
for a secure certificates to access the phone location- a location spoofer for mocking
Some concepts taught:
Navigator.geolocation
fromGeolocation API
recommandationwatchPosition()
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')
})