Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zoom MKMapView to an MKAnnotationView's frame

I have a grouped pin that I want to zoom in on. Of course I know the coords of the pin, and have it's view rect. I just want to zoom the map to just the right region so that the cluster fully expands showing all pins (plus a bit of padding). What's a good way of doing this?

Sidenote:
In my setup the cluster pin will automatically be expanded into individual pins when the zoom level increases so I'm good there. What I need to know is how to set the MapView to a new region based on the frame and coords of the cluster pin.

enter image description here

like image 435
eric Avatar asked Mar 16 '13 19:03

eric


1 Answers

You can use:

mapView.showAnnotations(groupedAnnotations, animated: true)

This method will zoom in and position the map automatically so the annotations are all visible.

like image 182
tanaschita Avatar answered Nov 02 '22 00:11

tanaschita