Added error handling and geolocation options

master^2
Keith Irwin 2019-02-21 21:00:05 -05:00
parent 9dd57845a8
commit d7a0b9a83d
No known key found for this signature in database
GPG Key ID: 7A2D6993A44010AA
1 changed files with 23 additions and 9 deletions

20
main.js
View File

@ -8,8 +8,10 @@ if (!'geolocation' in navigator) {
speedDiv.innerHTML = 'No API'
} else {
const WID = navigator.geolocation.watchPosition( function (loc) {
// got speed
const WID = navigator.geolocation.watchPosition(
// Success
function (loc) {
if (loc.coords.speed) {
console.log('Got speed:',loc.coords.speed)
// convert to mph and display
@ -17,5 +19,17 @@ if (!'geolocation' in navigator) {
} else {
speedDiv.innerHTML = '0.0'
}
})
},
// Error
function() {
console.error('Could not determine GPS position')
},
// Options
{
enableHighAccuracy: true,
}
)
}