javascript - 如何获得用户当前位置的最大准确性

标签 javascript geolocation

我正在使用此代码来获取准确的用户位置...

watchID=navigator.geolocation.watchPosition(handleGetCurrentPosition, handleGetCurrentPositionError, {enableHighAccuracy:true});

function handleGetCurrentPosition(location)
{   
    document.getElementById("lat").value = location.coords.latitude;
    document.getElementById("lon").value = location.coords.longitude;
    document.getElementById("accu").value =location.coords.accuracy;
    document.forms["myform"].submit();
}

function handleGetCurrentPositionError(){
    alert("Location could not be found.")
}

bt 我得到的结果不准确。 我使用的代码有什么问题吗?

最佳答案

准确性取决于您的地理定位设备的功能。 navigator.geolocation 只是一个与该设备配合使用的 API。如果设备不支持高精度,您将无法使用它执行任何操作。

关于javascript - 如何获得用户当前位置的最大准确性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11327083/

相关文章:

javascript - Dir步行获取各种文件的abs路径数组

javascript - 如果 href 与变量匹配,则将类添加到菜单 li

javascript - 伪类继承相对于函数继承(工厂函数)有哪些技术优势?

ios - CLLocation Manager 委托(delegate)问题

javascript - 嵌入式 Flash 在移动设备上不起作用

javascript - 在大量渲染/计算期间卡住后如何防止滚动位置跳跃?

查找覆盖 X 百分比地理点的最小区域的算法

javascript - 如何获取用户的位置?

javascript - 通过html5地理位置获取天气

javascript - 如何使用地理位置而不是完整的国家和地区名称来获取国家和地区代码