I have a code snippet that checks for GeoLocation API. If it's available, I try to get current position. But depending on the browser, code works differently:
- in IE, successCallback is called with every F5 refres
- in FF, I get successCallback or errorCallback with error code = 2 (POSITION_UNAVAILABLE)
- in Chrome I get successCallback or... nothing. I wait and wait and nothing
Actually I need successCallback to be called in some consistent manner... Is there a change to achieve it?
Code snippet:
function successCallback(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
alert("Your location is: " + latitude + "," + longitude);
}
function errorCallback(error) {
console.log(error);
}
if (Modernizr.geolocation) {
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, { maximumAge: 0 });
alert("geolocation is enabled");
} else {
alert("geolocation is NOT enabled");
}
Quick note 1:
alert("geolocation is enabled");
is called every time.
Quick note 2:
setting:
maximumAge: 1
works better. Now Chrome & IE call successCallback every time. Only FF freaks me out, it calles successCallback randomly.