2012-10-16 62 views
0

我对phoneGap非常陌生,正在使用以下代码来观看用户的位置。如何获取用户每一小时的当前位置?

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

但问题是成功的回调触发,每一个second.I只想把用户的位置,每一个hour.Please建议我

回答

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'); 
}