【发布时间】:2015-08-01 17:19:38
【问题描述】:
我有一个测试应用程序,它从 HTML5 地理定位服务获取 lat/lng 值。不幸的是,它以相当不一致的时间间隔发射,从 500 毫秒到 10000 毫秒不等。我已经尝试更改手表的 maximimAge 和 timeout 参数,但这些似乎并没有改变任何东西。我正在 Chrome 中以及通过 Android Lollipop 构建上的简单 Cordova 应用程序对其进行测试。下面的代码仅显示手表的时间戳值,以消除可能导致问题的任何其他延迟。似乎该间隔接近 1 秒然后 5 秒的重复模式。我还尝试将地理位置获取函数放在 setInterval 函数中,它的行为具有相同的 1 秒和 5 秒重复间隔。
<html>
<body>
<h1>Timestamp</h1>
<div id="mytimestamp"></div>
<button id="btnstopwatch">Stop GPS</button>
</body>
</html>
<script type="text/javascript">
var mytimestamp = document.getElementById("mytimestamp");
//start watching location
watchPositionId = navigator.geolocation.watchPosition(updateCompass,handleerror,{
enableHighAccuracy:true,
maximumAge:3000,
timeout:3000
});
function updateCompass(p)
{
mytimestamp.innerHTML = p.timestamp;
}
function handleerror(err)
{
if(err.code ==1)
{
//user said no
alert('Please allow access to GPS');
}
else
{
alert(err.code);
}
}
</script>
【问题讨论】:
标签: javascript html cordova geolocation