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

여기서 상기 업데이트 또는 에러에 기초하여 호출 두 함수의 샘플이다

관련 문제