When asking the browser for permission to access the current position, what is the best way to determine if the user has either ignored the browser prompt, or selected the “Not now” option?
The timeout doesn’t seem to fire for this case.
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
currentLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
callback();
}, function() {
currentLocation = default_location;
callback();
},{timeout: 5000});
}
A solution I’m using now is to use a default location for currentLocation and refresh the page/view anytime one of the callbacks is fired due to the user answering the browser prompt.
The 5 second timeout you’re specifying doesn’t start until the user has taken action, per the HTML5 geolocation spec.
The second callback function should be firing as soon as the user clicks “deny” in their browser, but nothing will be fired if the user ignores the prompt and lets it sit. The traditional implementation is to assume that a user doesn’t have geolocation capabilities and won’t click on the prompt, using it more as an enhancement than a required feature.
Alternatively, you could design the page to help guide users to take action, throwing a dark div masking the entire page with “Click up here” text.