I'm developing a web app for mobile and using html5's geolocation api.
When the page is loaded I start a watch position:
function enableWatchPosition() {
if (navigator.geolocation) {
watchPositionId = navigator.geolocation.watchPosition(locateByBrowser, handleErrorGettingLocation, {
timeout : 30000,
enableHighAccuracy : true,
maximumAge : 1000
});
}
}
If a user doesn't have his GPS on, handleErrorGettingLocation
is triggered and I show him an error message, asking him to turn GPS on.
My Question is:
Suppose the user then turns his GPS on - how can I detect that (so I could retry and call enableWatchPosition()
again)? Is there some sort of js event I can listen to?
Thanks!
There is no such event that’s exposed in a way you could see from your Web-application code. Certainly there is no such event defined in the standard Geolocation API spec. And I don’t believe there are any non-standard events that any browsers expose for it. So I don’t think you’re going to be able to automatically re-trigger a call to your enableWatchPosition()
function.
I’m sure that’s not the answer you were hoping for, but it is the answer. :-(