开发者

How to refresh or move pin when user gets current location

开发者 https://www.devze.com 2023-03-06 04:24 出处:网络
I am working on an application which use user location updates, I havegot the current latitude and longitude and display the current location of the user and annotate the pin, However I need help rega

I am working on an application which use user location updates, I have got the current latitude and longitude and display the current location of the user and annotate the pin, However I need help regarding moving a pin when user changes his location or when user moves and get new latitude and longitude the pin should also move 开发者_运维技巧to that position.


To show the current location, you could just set showsUserLocation to YES and let the map show the blue dot for you.

If you want to show your own annotation instead and have it move automatically, implement setCoordinate: in the class that implements the MKAnnotation protocol.

Then when the coordinates change, update the annotation's coordinate and the map view will automatically (via KVO) move the annotation's view/pin.

You could also remove the annotation and create a new one at the new location but that can result in flicker.

If you are using Core Location to get location updates, you would update the annotation's coordinates in the locationManager:didUpdateToLocation:fromLocation: delegate method.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号