0

I used following code to get user current location. This was work fine in localhost chrome and safari but I face issue with firefox. If I allow to share my location in firefox latest browser it work nicely. But I not allow, it not work. Can anyone please explain me what is the reason for that.

function getLocation() {
    // Check for geolocation support
    if (navigator.geolocation) {
        // Get current position
        navigator.geolocation.getCurrentPosition(function (position) {
            // Success!
            initialize(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));
        },
        function () {
            // Gelocation fallback: Defaults
            initialize(new google.maps.LatLng(40.712784, -74.005941));
        });
    }
    else {
        // No geolocation fallback: Defaults
        initialize(new google.maps.LatLng(40.712784, -74.005941));
    }
}
nithin
  • 153
  • 15

1 Answers1

0

This bug has been filed to Mozilla few years ago (https://bugzilla.mozilla.org/show_bug.cgi?id=675533)

Once the script invokes getCurrentPosition(), Firefox prompts the user to share his/her geolocation. At this point, if the user rejects the request, Firefox unfortunately does not acknowledge the callback function with rejection response. Therefore, your fallback condition will never fire.

However, there doesn't appear to be any solution provided for this known bug just yet.

Some people have been aware of this issue, see (function fail never called if user declines to share geolocation in firefox). One of viable workarounds for this issue would be using timeout (see details in the link).

Community
  • 1
  • 1
TaoPR
  • 5,932
  • 3
  • 25
  • 35