Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make html5 geolocation ask permission every time user reloads the page

Why we need that:

We have some page in our website which allows users to enter some data and search for another customers in their area. When user opened that page the popup message must be shown

http://foo.bar.com would like to use your current location.

After that user can discard that and fill the location fields manually or accept and be automatically redirected to results page.

Problem:

The problem is that when user selects any of the mentioned options at first time, browser remembers it and don't ask it next time. So when user accept it, every time he open the search page it will automatically redirect him to results page withous asking anything.

Code:

We are using basic html5 geolocation code

if (navigator.geolocation) {
   navigator.geolocation.getCurrentPosition(LocationMethod);
} 

Conclusion:

I'm pretty sure that it's impossible to change permission that are browser-native. But I hope that someone will give nice solution for this problem. Thanks.

like image 901
Chuck Norris Avatar asked May 03 '13 07:05

Chuck Norris


1 Answers

once a user clicks deny/allow the browser remembers this decision for the site.

the best way to avoid a deny is to only call getCurrentPosition(...) when the user clicked something that means he wants to use his location. and then he would probably be glad to share it :)

A good example is on foursquare site. on entering it offers you to go to the map to some city, and only there by clicking the button on the map of "use my location" it prompts for it.

If you are denied the location you could also show an info message with "you have denied location service in the past for this site, do enable it do bla bla bla". and fill in the bla bla bla with whatever.

like image 129
samz Avatar answered Nov 17 '22 06:11

samz