How to move a MKAnnotation without adding/removing it from the map?

DevDevDev picture DevDevDev · Feb 13, 2010 · Viewed 19.7k times · Source

Is it possible to move the coordinate of a MKAnnotation without adding and removing the annotation from the map?

Answer

spstanley picture spstanley · Jul 5, 2010

I found a pretty simple method. I wanted to update my player's position smoothly without removing and then re-adding the player annotation. This works well for pre-iOS4 apps, and what it does is both move the pin and center the map on the pin's new location:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[player setCoordinate:aLoc.coordinate];
[mapView setCenterCoordinate:aLoc.coordinate animated:NO];
[UIView commitAnimations];

Here's the same thing but using the recommended block feature for iOS4:

[UIView animateWithDuration:0.5 animations:^{
    [player setCoordinate:aLoc.coordinate];
    [mapView setCenterCoordinate:aLoc.coordinate animated:NO];
}];