我有这个函数navigator.geolocation.getCurrentPosition(onSuccess, onError, { frequency: 1000 })
在我的申请中。我已经实现了onSuccess
和onError
方法(参数)的代码。
这里除了{frequency:3000}
参数,其他都是工作的。我的代码显示了onSuccess
方法模拟器上的经度和纬度。对于失败,在模拟器上设置onError
。但是这里{frequency:3000}
不起作用。我也用maximumAge:2000
代替频率。我的应用程序的Moto每30秒更新一次服务器上的信息。但frequency
和maximumAge
不工作
<!DOCTYPE html>
<html>
<head>
<title>Device Properties Example</title>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
// onSuccess Geolocation
//
function onSuccess(position) {
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude
+ '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'Altitude: ' + position.coords.altitude + '<br />' +
'Accuracy: ' + position.coords.accuracy + '<br />' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br />' +
'Heading: ' + position.coords.heading + '<br />' +
'Speed: ' + position.coords.speed + '<br />' +
'Timestamp: ' + new Date(position.timestamp) + '<br />';
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + 'n' +
'message: ' + error.message + 'n');
}
</script>
</head>
<body>
<p id="geolocation">Finding geolocation...</p>
</body>
</html>
例如,您还可以添加如下内容:
setTimeout("navigator.geolocation。getCurrentPosition(onSuccess, onError);", 3000);
在你的'OnSuccess'方法的末尾,每隔3秒自动刷新你的地质数据。