2

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).

  1. Is it possible to prevent the browser location check?
  2. If not, is there an event that can be catched, so I can change where the map jumps to?

Airbnb.com uses Google Maps as well, and there the browser never asks for the user location.

Any advices?

Primi
  • 127
  • 1
  • 10

1 Answers1

4

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

Community
  • 1
  • 1
bviale
  • 5,245
  • 3
  • 28
  • 48
  • Thanks for your helpful input! Since our page is somehow similar to airbnb, we don't need the user location, because the markers on the map depend on the search input. Using the geolocation by IP address sounds interesting, but I am not quite sure how to use it respectively how to combine it with google maps. Have you tried this before? – Primi Mar 09 '15 at 15:51
  • Never tried this before, but there is more explanations about this in this thread : http://stackoverflow.com/questions/4937517/ip-to-location-using-javascript But it seems kind of dirty, is it a real need in your case ? – bviale Mar 09 '15 at 15:53
  • No not really, I just want to get rid of the browser location check, since I don't need the current location. – Primi Mar 09 '15 at 16:00
  • Wait, you don't need the user geolocation ? I don't get your point – bviale Mar 09 '15 at 16:04
  • No I don't need the user location, because I get several positions from our backend (depending on the search keyword) and just use fitBounds() to adjust the map correctly. – Primi Mar 09 '15 at 16:09
  • Ok, so to be clear : you just want to use Gmaps to display your backend points, and you are annoyed by the ask of permission to get user geolocation by Gmaps whereas you don't need it, right ? – bviale Mar 09 '15 at 16:12
  • 1
    Okay, way more clear, please make an example of your code on jsfiddle so we can see where there is something asking for user geolocation, I can't do more without your code. Cheers – bviale Mar 09 '15 at 16:27