Skip to content

Instantly share code, notes, and snippets.

@dieface
Forked from andrewgleave/iOSMapKitFitAnnotations.m
Last active August 29, 2015 14:08
Show Gist options
  • Save dieface/3d5aea613ec61db4d87c to your computer and use it in GitHub Desktop.
Save dieface/3d5aea613ec61db4d87c to your computer and use it in GitHub Desktop.
MKMapRect zoomRect = MKMapRectNull;
for (id <MKAnnotation> annotation in mapView.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];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment