Reputation: 14998
I am using following code:
var fail = function(error) {
alert("Unable to get location");
};
function getGeo() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
success,
fail,
{maximumAge: 50000, timeout: 30000, enableHighAccuracy: true});
}
};
Mostly It works but often it gives geolocation error and unable to get coordinates.
How can I make possible to get coordinates no matter browser window is inactive or browser is in background or mobile itself in sleep mode?
Upvotes: 0
Views: 333
Reputation: 1264
Without specifics of "geolocation error" my answer can no be complete but: -
At present you cannot get coordinates if browser window is inactive or browser is in background or mobile itself in sleep mode, unless you are developing a hybrid App with something like phonegap/cordova. (Firefox has the exception of continuing to service watchPosition() if the App is foregrounded but the phone is asleep.)
I have made several suggestions to W3C, IETF, Chrome Dev, Mozilla Dev, and Edge Dev regarding a workable solution using the Service Worker Extensibility functionality for a Javascript-only solution.
Briefly, the UA tracks Geolocation changes and if within range of a dev supplied filter, a ServiceWorker will be instantiated which may foreground the App or merely notify the App Server.
Please pursue this issue with the relevant bodies as the idea is beginning to gain traction.
HTH
Upvotes: 1