0

私は phoneGap を初めて使用し、次のコードを使用してユーザーの位置を監視しています。

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

しかし、問題は、成功のコールバックが 1 秒ごとにトリガーされることです。1 時間ごとにユーザーの位置を取得したいだけです。提案してください

4

1 に答える 1

0

これはどう:

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

上記が更新またはエラーに基づいて呼び出す 2 つの関数のサンプルを次に示します。

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 に答える