IOS: zoom in mapkit for two annotation point

ios, mapkit, xcode

Solution

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];

Problem

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

Original source

Related problems