0

我对 phoneGap 非常陌生,并且正在使用以下代码来查看用户的位置。

var options = { enableHighAccuracy:true , frequency : 30000 };
watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);

但问题是每隔一秒触发一次成功回调。我只想每隔一小时占据用户的位置。请建议我

4

1 回答 1

0

这个怎么样:

var controller=this;
navigator.geolocation.watchPosition(controller.onLocationUpdate, controller.onLocationError, {enableHighAccuracy:true, maximumAge: 3600000, timeout: 5000});

以下是上面将根据更新或错误调用的两个函数的示例:

onLocationUpdate: function(geo) {
    console.log('location update');
    this.latitude = geo.coords.latitude, this.longitude = geo.coords.longitude, this.accuracy = geo.coords.accuracy, this.altitude = geo.coords.altitude, this.altitudeAccuracy = geo.coords.altitudeAccuracy, this.heading = geo.coords.heading, this.speed = geo.coords.speed;
},
onLocationError: function() {
    console.log('Location Error');
}
于 2012-10-17T13:28:05.523 回答