When a user clicks on my site, I check to see if I have a location session in PHP. If the session is not established with the users location, I redirect them to the site www.domain.net/location. There are several user choices on this page. If the browser allows you to use one of the options, use the browser to install it. The code below works very well.
The problem I ran into is that as soon as the user has allowed the browser to share the location, it looks like it is installed forever. While the user is browsing, they may decide to change their location, then click a button to go back to www.domain.net/location. Without any tooltips, it automatically selects the location of browsers and redirects them. There are other location parameters on the page, including an interactive map, I really need to be able to reset, expire, delete, force something, so that the browsers again ask if the user wants to use the browser to set the location or allow the user to use one of the other options.
The only thing I can think of is to move the actual Javascript below to another page, and on the page www.domain.net/location there is another button that says something like “Use my exact location” and then will link to JS below.
Does anyone know of another way to reset this or something else?
<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; </script>
javascript html5 geolocation location
James mills
source share