如何过期或重置地理位置 [英] How to expire or reset geolocation

查看:142
本文介绍了如何过期或重置地理位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击我的网站时,我检查是否有用PHP设置的位置会话。如果没有设置用户位置的会话,我将它们重定向到www.domain.net/location。在这个页面上,有许多用户选择一个位置的选项。如果浏览器允许,其中一个选项是使用浏览器来设置。下面的代码工作得很好。

我遇到的问题是,一旦用户允许浏览器共享位置,这似乎永久设置。当用户浏览时,他们可能会决定更改他们的位置,然后点击一个按钮再次进入www.domain.net/location页面。如果没有任何弹出窗口,它会自动获取浏览器的位置并重定向它们。在页面上还有其他位置选项,包括可点击的地图,我需要重置,过期,删除,强制某些内容,以便浏览器再次询问用户是否要使用浏览器设置位置或允许用户可以使用其他选项之一。



我能想到的唯一方法是将下面的实际Javascript移动到另一个页面上以及www.domain.net/位置页面上有另一个按钮,表示使用我的精确位置,然后链接到下面的JS。



有没有人知道重置这种方法的另一种方式,或者

 < script type =text / javascriptcharset =utf-8> 


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

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

// alert('找到的位置:'+ lat +','+ lng);
window.location =http://www.domain.net/?lat=+ lat +& lng =+ lng;


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

findLocation();


< / script>


解决方案

这是每个浏览器的设置,你可以在脚本端进行控制。您可以做的是提供链接,例如这一个说明了如何更新特定网站的地理位置设置。

/ location ,但链接到 / location?update 或类似的东西。本质上,转到位置页面,但添加一些防止自动重定向的内容,以便用户可以对他们的位置做出不同的决定。


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>

解决方案

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.

这篇关于如何过期或重置地理位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆