I am trying to use HTML5 gelolocation to get the current visitor's location. Due to privacy, the browser will prompt the user to allow/disallow sharing their location with the site.
If the user does NOT allow sharing their location, I want to display a message to the console.
Here is what I have done
$(function() {
// Try HTML5 geolocation.
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function(position)
{
findClosestStore(position.coords.latitude, position.coords.longitude);
}, displayMapWithAddressBar);
}
else
{
// Browser doesn't support Geolocation
console.log('browser does not support geolocation!')
displayMapWithAddressBar();
}
});
function displayMapWithAddressBar()
{
console.log('Show the map since the location was not detected!');
}
But when the user refuse to share their location, I don't see anything in the console. I expect to see a message to say Show the map since the location was not detected!
How can I know that a user refused to share their location?
UPDATE
My code work as expected in google Chrome but not in Firefox. How can I get this to work in all browsers?