If you update the coordinate of an annotation using the setCoordinate (or equivalent) method, the map view automatically updates the position of the annotation on the view. This page in the docs reads as follows:
Important: when you implement the Coordinate property in your class, it is recommended to synthesize its creation. If you decide to implement the methods of this property yourself, or if you manually change the variable underlying this property in other parts of your class after the annotation is added to the map, be sure to send the observation key-value (KVO) when you do it. The Map Kit uses KVO notifications to detect changes in the coordinate, name and subtitle properties of annotations and make all necessary changes on the map display. If you do this, do not send KVO notifications, the position of your annotations cannot be updated correctly on the map.
The map display will only know to re-read the annotation coordinate property if it reports (via KVO) that the coordinate has changed. One way to do this is to implement the setCoordinate method and call it wherever you have code that updates the location of the annotation.
In your code, you recalculate the coordinate in the readonly coordinate property of your own. What you can do is add this to your .m annotation file (and in .h):
- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate {
and in the place where you update the locations, call the setCoordinate method in the annotation:
[someAnnotation setCoordinate:someAnnotation.coordinate]
You can do this where you are currently deleting / re-adding annotations.
The above call looks funny because you translate the coordinates into a coordinate getter method. Although it should work as a quick fix / test, I do not recommend using it regularly.
Instead, you can re-calculate the location of the annotations outside (where you are currently deleting / re-adding annotations) and pass the new coordinate to setCoordinate. Your annotation object could save its new location in the / lng ivars paws that you have (set them in setCoordinate and use only those that are designed to create CLLocationCoordinate2D to return from the getter) or (better) use the ivar coordinate itself (set it in setCoordinate and return it to getter).
Anna Nov 06 '10 at 16:11 2010-11-06 16:11
source share