How to expire or reset geolocation

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; //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> 
+8
javascript html5 geolocation location
source share
4 answers

This is a setting for each browser, not something you can control on the side of the script. What you can do is provide a link such as this one that explains how to update geolocation settings for specific sites for a given browser.

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

+2
source share

I admittedly played a couple of times with the Javascript Location API, but I understand that the browser saves the user's preferences (this assumption seems to be reinforced here ).

The cited page assumes that the user's preference is stored based on each site (domain), and not on the URL. If this is not the case, adding a randomized string value to the URL should do the trick. EDIT: I checked and exceptions are defined for each domain:

This would make your suggestion to put the code on another page - or attach it to an event that does not fire on the page - this is the best solution that I can imagine from hand.

+1
source share

If a user gives permission to your site to use his location, he simply saves "allow" along with the URL of your site in the browser security settings. It does not save the actual location. This is done using code. If you want to use the new location, just get it using javascript.

 navigator.geolocation.getCurrentPosition(function(position) { do_something(position.coords.latitude, position.coords.longitude); }); 

More on getting geolocation: https://developer.mozilla.org/en-US/docs/WebAPI/Using_geolocation

If you save the location in a cookie and reuse this place, simply clear your cookie and reset, or don’t use cookies at all.

To view Chrome’s geolocation repository settings, go to Chrome’s Triple Bar> Preferences> Advanced ... in the Privacy section, click Content Settings> Location, select Manage Exceptions.

+1
source share

I decided to add? change-location to the end of the url and use php to check this and then hide javascript on the page. This is not very good, but it seems that this is a setting for each browser, and not that you can reset using a script. It would seem that as soon as the user said "remember my preference", then this is what he will do until they delve into the setting and change it in their browser.

0
source share

All Articles