"User has not allowed access to Windows Location" error in browser for React JS application

Viewed 942

I am building application to get user address from google map based on its location co-ordinates from browser geolocation API. I have used below code to get co-ordinates. Popup is shown to allow permission for location on first time. I have allowed permission to access location in browser. Still it is not working.

useEffect(() => {
    if ("geolocation" in navigator) {
        console.log("Available");
    } else {
        console.log("Not Available");
    }

    navigator.geolocation.getCurrentPosition(function(position) {
        //do success handling
        console.log(position);
        console.log("Latitude is :", position.coords.latitude);
        console.log("Longitude is :", position.coords.longitude);
     },
     function errorCallback(error) {
        //do error handling
        console.log(error);
     },
     {
        timeout:5000
     });
)}

if condition gives Available output, but getcurrentposition() always returns error "User has not allowed access to Windows Location"

1 Answers

The backend of geolocation query (API) is built by individual browser manufacturer. That includes the permissions design and where it is queried.

The error you are receiving seems to be Microsoft Edge (if I am correct).

Microsoft Edge: Site level user permission alone is not enough. User must also go to Windows settings > Location > Enable location + Enable apps can access location. Edge will check for Windows permissions first and then query its own API servers for geolocation.

Chrome & Firefox: Once user allows location permission for the site, you are all set. Google and Mozilla will query their respective servers for geolocation.

Related