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

32
main.js
View File

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