问题
What is the difference between getCurrentPosition()
and watchPosition()
. I read several articles about getCurrentPosition()
and watchPosition()
. But none of was clear to me. As far as I'm understand getCurrentPosition()
update location only one time But watchPosition()
continuously update location. I'm I right??
回答1:
getCurrentPosition()
gives currentPosition latitude and longtitude values,which fires only once. Where as watchPosition()
gives currentPosition latitude and longtitude values continuously. If position changed(assume you are in a moving vehicle,then watchPosition()
will give result.Then you will come to know the result of this )
回答2:
You are correct. The getCurrentPosition()
callback is fired once and watchPosition()
callback is fired continuously. Good reading on this here.
回答3:
watchPosition
fired each time your device position changes (with interval specified in fn params). getCurrentPostion
only once.
watchPosition
actually analogue of setInterval
fn and also returns id that can be used to stop iterative process by using clearWatch
.
来源:https://stackoverflow.com/questions/13324165/watchposition-and-getcurrentposition