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