Take the 2-minute tour ×

I want to know if there is a way to have a dynamic zoom when I set in my mapview the blue dot (my position) and another pin...when I load mapview I want to show these two point in the same frame...is it possible? thanks

share|improve this question

1 Answer 1

up vote 8 down vote accepted

Yes, it is possible. After adding the second annotation. This sample code should work for any number of annotations:

MKMapRect zoomRect = MKMapRectNull;
NSArray *annotations = [mapView annotations];
for (MKAnnotation *annotation in annotations) {

    MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
    MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
    if (MKMapRectIsNull(zoomRect)) {
        zoomRect = pointRect;
    } else {
        zoomRect = MKMapRectUnion(zoomRect, pointRect);


[mapView setVisibleMapRect:zoomRect animated:YES];
share|improve this answer
it's better.....stackoverflow.com/questions/4680649/… –  nazz_areno May 18 '12 at 9:19
Thank you, really useful, i only need to modify the type of the variable "annotation" from MKAnnotation to MKPointAnnotation and works ;)! –  MansApps Mar 20 at 15:15

Your Answer


