Reputation: 2924
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!
Upvotes: 1
Views: 33818
Reputation: 870
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
Upvotes: 3
Reputation: 2924
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..
Upvotes: 8
Reputation: 4758
If you are using chrome, please have a look at the answer below:
HTML 5 Geo Location Prompt in Chrome
Upvotes: 1