Reputation: 127
We are implementing a website using AngularJS and Google Maps API. The user can enter a keyword and is then redirected to a new page, which contains a map with several markers (representing the results). On this result page the browser always asks for the user location. When the user selects "deny", then the map jumps to the position 0,0 (somewhere in the sea).
Airbnb.com uses Google Maps as well, and there the browser never asks for the user location.
Any advices?
Upvotes: 2
Views: 2874
Reputation: 5375
Is it possible to prevent the browser location check?
No, for obvious security reasons, it is impossible to disable this check from JavaScript. But, it is possible for the user to "remember" the choice to allow access to location from Chrome.
If not, is there an event that can be catched, so I can change where the map jumps to?
You can do something like navigator.geolocation.getCurrentPosition(showPosition,showError);
with
function showError(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
x.innerHTML = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML = "Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML = "An unknown error occurred."
break;
}
}
Edit : For the AirBnB thing, it is possible to use another type of geolocation by IP adress, which does not require any permission but it lacks of precision. See this thread for details about geolocation by IP
Upvotes: 4