Make html5 geolocation ask permission every time user reloads the page

18,392

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.

Share:
18,392
Chuck Norris
Author by

Chuck Norris

First of all, I'm a human being! And only after that Chuck Norris :) In this world we should help to get help from others! #SOreadytohelp

Updated on July 19, 2022

Comments

  • Chuck Norris
    Chuck Norris almost 2 years

    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.