Search code examples
iosmkmapviewmkannotationview

showing callout after moving mapview


I have several annotations on a mapview. After selecting one of them (callout enabled) I want the map to center on it. I call[mapView setCenterCoordinate:coordinate animated:YES];in didSelectAnnotationViewto achieve that.

It works but not always - basically when there is not enough room left to show the callout, the map moves and the annotation is selected, but the callout is not shown (doesn't matter if the move is animated or not). If I don't move the map myself with setCenterCoordinate, after selecting a annotation the map gets automatically moved (just slightly) to show the callout and it works everytime.

Any ideas how to make it work in my case? To sum up I want to center the map on the selected annotation and show the callout.


Solution

  • Solved it by calling setCenter with a slight delay in didSelectAnnotationView:

    dispatch_time_t dt = dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC);
    dispatch_after(dt, dispatch_get_main_queue(), ^(void)
    {
        [mapView setCenterCoordinate:view.annotation.coordinate animated:YES];
    });