1

I'm trying to take the geolocation of the User and then do a query. In Mozilla Firefox it works fine also in Safari.... but in Chrome it doesnt work at all.

window.onload = function(){
  if(navigator.geolocation){

    navigator.geolocation.getCurrentPosition(function(position){

        var latitude = position.coords.latitude,
            longitude = position.coords.longitude;
      console.log(latitude + " " + longitude);

    },handleError);

    function handleError(error){
      //Handle Errors
     switch(error.code) {
        case error.PERMISSION_DENIED:
            console.log("User denied the request for Geolocation.");
            break;
        case error.POSITION_UNAVAILABLE:
            console.log("Location information is unavailable.");
            break;
        case error.TIMEOUT:
           console.log("The request to get user location timed out.");
            break;
        case error.UNKNOWN_ERROR:
           console.log("An unknown error occurred.");
            break;
    }
    }
  }else{
    // container.innerHTML = "Geolocation is not Supported for this browser/OS.";
    alert("Geolocation is not Supported for this browser/OS");
  }
};

And i get the error 1

User denied the request for Geolocation.

But i haven't denied any request, actually the popup window doesnt come up at all.

I've went to Chrome Settings > Show advanced > Privacy > Content Settings > Location allow for all.

Restarted chrome and nothing happened. I'm sure my code is 100% legit so does anyone know how to deal with it? Thanks!

Konstantinos Natsios
  • 2,874
  • 9
  • 39
  • 74

3 Answers3

8

Ok this was quite easy... Chrome since 20 of April 2016 has disabled the Geolocation API for insecure websites (without https)... link here

https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only

So dont worry..

Konstantinos Natsios
  • 2,874
  • 9
  • 39
  • 74
3

The easiest way is to click on the area left to the address bar and change location settings there. It allows to set location options even for file:/// and all other types

enter image description here

Marina Dunst
  • 859
  • 1
  • 6
  • 19
  • This setting kept resetting to "Blocked" the instant I clicked allow. Turned out my mac's system wide settings was disabling it. System preferences > Security and privacy > Privacy > Location Services > Enable Chrome – Kevin S May 29 '22 at 07:14
1

If you are using chrome, please have a look at the answer below:

HTML 5 Geo Location Prompt in Chrome

Community
  • 1
  • 1
Atal Kishore
  • 4,480
  • 3
  • 18
  • 27