如何获取用户每小时的当前位置?

时间:2012-10-16 06:59:38

标签: jquery cordova sencha-touch

我是phoneGap的新手,我正在使用以下代码观看用户的位置。

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

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

1 个答案:

答案 0 :(得分: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');
}