How to expire or reset geolocation

geolocation, html, javascript, location

Solution

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.

Problem

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> ```

Original source