我正在尝试使用以下代码获取用户的GeoLocation:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$(function() {
var Geo={};
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(success, error);
}
//Get the latitude and the longitude;
function success(position) {
Geo.lat = position.coords.latitude;
Geo.lng = position.coords.longitude;
populateHeader(Geo.lat, Geo.lng);
}
function error(){
console.log("Geocoder failed");
}
function populateHeader(lat, lng){
$('#Lat').html(lat);
$('#Long').html(lng);
}
});
</script>
</head>
<body>
<div class="geo-coords">
GeoLocation:
<span id="Lat">lat: ...</span>°,
<span id="Long">long: ...</span>°
</div>
</body>
</html>我在传统的台式电脑上试了试,似乎工作正常(由于缺乏全球定位系统传感器,除了一些近似值),在我的移动火狐S4 Mini上也是如此,但在最后一个案例中,我怀疑位置总是由Wi-Fi或移动连接而不是全球定位系统传感器确定的。事实上,即使我打开和关闭GPS,我的智能手机的位置几乎总是相同的,与谷歌地图上相同的GPS检测到的实际确切位置有很大的不同。
如何确定GPS传感器是默认使用的传感器?
或者,为了跟踪用户设备的位置,您有什么其他建议吗?谢谢
发布于 2014-03-13 01:10:26
基本上,您只能获取API提供的信息,并快速查看API文档:dev.w3.org我想您能做的最好的事情就是检查coords.accuracy。
另外,请记住将enableHighAccuracy设置为启用,这样您就可以获得更准确的值。
https://stackoverflow.com/questions/22345217
复制相似问题