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
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With