Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expire or reset geolocation

When a user hits my website I check to see if I have a location session set in PHP. If there is no session set with the users location in I redirect them to www.domain.net/location. On this page there are a number of options for the user to pick a location. If the browser allows it one of the options is to use the browser to set this. The below code works really well.

The issue I am having is that once a user has allowed the browser to share the location this seems to be set forever. Whilst the user is browsing they may decide to change their location so they then click a button to go to the www.domain.net/location page again. Without anything popping up it automatically picks up the browsers location and redirects them. There are other location options on the page including a clickable map, I really need to be able to reset, expire, delete, force something so that the browsers asks again if the user wants to use the browser to set the location or to allow the user to use one of the other options.

The only thing I can think of is to move the actual Javascript below onto another page and on the www.domain.net/location page have another button that says something like 'Use my precise location' and that would then link to the JS below.

Does anyone know of another way of resetting this or something?

<script type="text/javascript" charset="utf-8">


    function findLocation()
    {
      var options = {timeout: 60000};
      navigator.geolocation.getCurrentPosition(foundLocation, noLocation, options);
    }

    function foundLocation(position)
    {
      var lat = position.coords.latitude;
      var lng = position.coords.longitude;

      //alert('Found location: ' + lat + ', ' + lng);
      window.location = "http://www.domain.net/?lat=" + lat + "&lng=" + lng;
    }

    function noLocation()
    {
      alert('Could not find location');
      window.location = "http://www.domain.net/location";
    }

    findLocation();


  </script>
like image 607
James Mills Avatar asked Feb 19 '13 11:02

James Mills


People also ask

How do I unblock a geolocation?

Android (Chrome)Touch Settings > Site settings > Location. Use the switch to either have Chrome ask before accessing your location, or to block all sites from accessing your location. Touch the specific blocked or allowed sites to manage exceptions.

What is geolocation error?

This error message appears when you use Internet Explorer and you do not allow the browser to submit information about your physical location. Make sure you are not overlooking Internet Explorer's prompt for permission to use geolocation. It usually appears near the bottom of your browser.

Why is geolocation not accurate?

There is no guarantee the geolocation information will be accurate, because this API can also use the IP address to infer user location in the absence of more accurate technologies, such as GPS receivers on the client's device. The browser exposes this API via the navigator.


1 Answers

This is a per-browser setting, not something that you can control on the script side. What you may be able to do is provide a link such as this one that explains how to update geolocation settings for particular websites for the given browser.

It seems like you can get around your specific problem not by linking to /location, but linking to /location?update or something like that. Essentially, go to the location page but add something that prevents the automatic redirect so the user can make a different decision about their location.

like image 188
Explosion Pills Avatar answered Sep 22 '22 00:09

Explosion Pills