2012-10-16 100 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'); 
}