Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.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
HTML5地理定位精度_Html_Geolocation - Fatal编程技术网

HTML5地理定位精度

HTML5地理定位精度,html,geolocation,Html,Geolocation,我正在使用HTML5地理位置Api 然后使用这个代码 <!DOCTYPE html> <html> <body> <p id="demo">Click the button to get your coordinates:</p> <button onclick="getLocation()">Try It</button> <script> var x=document.getElement

我正在使用HTML5地理位置Api 然后使用这个代码

<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to get your coordinates:</p>
<button onclick="getLocation()">Try It</button>
<script>
    var x=document.getElementById("demo");
    function getLocation()
    {
        if (navigator.geolocation)
        {
            navigator.geolocation.watchPosition(showPosition,error,{ enableHighAccuracy: true, timeout: 150000, maximumAge: 0 });
        }
        else
        {
            x.innerHTML="Geolocation is not supported by this browser.";
        }
    }
    function showPosition(position)
    {
        x.innerHTML = 'Latitude: '  + position.coords.latitude      + '<br />' +
            'Longitude: ' + position.coords.longitude     + '<br />' +'Acc: ' + position.coords.accuracy     + '<br />'+
            '<hr />'      + x.innerHTML;
    }
    function error(err){alert(err);}
</script>

单击按钮获取您的坐标:

试试看 var x=document.getElementById(“演示”); 函数getLocation() { if(导航器.地理位置) { navigator.geolocation.watchPosition(showPosition,error,{enableHighAccurance:true,timeout:150000,maximumAge:0}); } 其他的 { x、 innerHTML=“此浏览器不支持地理位置。”; } } 功能显示位置(位置) { x、 innerHTML='Latitude:'+position.coords.Latitude+'
+ '经度:'+position.coords.Longitude+'
'+'Acc:'+position.coords.accurity+'
'+ “
”+x.innerHTML; } 函数错误(err){alert(err);}

当我在codein
Chrome
FireFox
上面运行时,它会给我精度值
122000
,而在
IE
中,它会给我15(哪个更合适) 因此,我在chrome中为获得更准确的结果所做的工作目前在主要浏览器中都得到了支持

  • Internet Explorer(9.0+)
  • Safari(5.0+)
  • Firefox(3.5+)
  • 歌剧院(10.6+)
  • 谷歌浏览器(取决于操作系统)
显然,您应该在任何受支持的浏览器中使用
navigator.geolocation.getCurrentPosition
来实现这一点

准确程度取决于浏览器供应商。您可能会从每一项中得到稍微不同的结果

另一个选择是MaxMind,这是一项免费服务,他们每个月的第一个星期二更新数据库。您可以检索二进制或cvs格式


对于移动浏览器,您可以查看一下,但是大多数现代移动浏览器也可以支持HTML5地理定位。

如果没有更高的准确度,就没有更高的准确度。实现地理定位取决于每个浏览器,有些浏览器可能比其他浏览器做得更好,有些浏览器可能在不同情况下比其他浏览器做得更好。