Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 地理位置重定向(HTML5)_Javascript_Html_Geolocation - Fatal编程技术网

Javascript 地理位置重定向(HTML5)

Javascript 地理位置重定向(HTML5),javascript,html,geolocation,Javascript,Html,Geolocation,我正在尝试创建一个脚本,根据位置重定向用户。我编写了这个脚本,地理定位工作,但重定向没有。为什么我不能重定向用户 <script> window.onload=function(){ if(navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition,showError); } else { alert("Geolocatio

我正在尝试创建一个脚本,根据位置重定向用户。我编写了这个脚本,地理定位工作,但重定向没有。为什么我不能重定向用户

<script>
    window.onload=function(){
    if(navigator.geolocation)
    {
    navigator.geolocation.getCurrentPosition(showPosition,showError);
    }
    else
    {
    alert("Geolocation is not supported by this browser.");
    }
    }
    function showError(error)
      {
      switch(error.code)
        {
        case error.PERMISSION_DENIED:
          alert("User denied the request for Geolocation.")
          break;
        case error.POSITION_UNAVAILABLE:
          alert("Location information is unavailable.")
          break;
        case error.TIMEOUT:
          alert("The request to get user location timed out.")
          break;
        case error.UNKNOWN_ERROR:
          alert("An unknown error occurred.")
          break;
        }
      }


    if (pos.coords.longitude >= 45.775534 && pos.coords.longitude <= 45.775562 && pos.coords.latitude <= 15.994809 && pos.coords.latitude >= 15.994792)
        {window.location = 'success.html';
        }
        else{
            window.location = 'other.html';
        }
    </script>

window.onload=function(){
if(导航器.地理位置)
{
navigator.geolocation.getCurrentPosition(showPosition,showError);
}
其他的
{
警报(“此浏览器不支持地理位置”);
}
}
功能错误(错误)
{
开关(错误代码)
{
案例错误。权限被拒绝:
警报(“用户拒绝了地理定位请求。”)
打破
案例错误。位置不可用:
警报(“位置信息不可用”)
打破
大小写错误。超时:
警报(“获取用户位置的请求超时”)
打破
案例错误。未知错误:
警报(“发生未知错误”)
打破
}
}

如果代码| pos |中未定义(pos.coords.longitude>=45.775534&&pos.coords.longitude,则需要定义函数showPosition()

功能显示位置(pos)
{

如果(pos.coords.longitude>=45.775534&&pos.coords.longitude)与上一个问题重复:。如果某个问题被关闭,请对其进行编辑,以便可以重新打开。不要再问它。
function showPosition(pos)
  {

   if (pos.coords.longitude >= 45.775534 && pos.coords.longitude <= 45.775562 && pos.coords.latitude <= 15.994809 && pos.coords.latitude >= 15.994792)
        {
            window.location = 'success.html';
        }
        else{
            window.location = 'other.html';
        }
  }