watchPosition() and getCurrentPosition

余生颓废 提交于 2019-12-22 20:43:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!