Merge pull request #1 from keith24/develop

Added error handling and geolocation options
master
Keith Irwin 2019-02-21 20:02:52 -06:00 committed by GitHub
commit 5bddb76667
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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,
}
)
}