Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enlarge MKCoordinateRegionForMapRect For some margin

I have some annotations presented on a map (somepoints) the map zooms in or out to fit all points - see working code below.

MKPolygon *poly = [MKPolygon polygonWithPoints:somepoints count:i];
[self.mapView setRegion:MKCoordinateRegionForMapRect([poly boundingMapRect]) animated:NO];

Q: I would like to expand this poly just slightly to have some margins, how can I enlarge this Region?

like image 394
chewy Avatar asked Dec 19 '22 17:12

chewy


1 Answers

You can increase the span of the region in order to add some margin:

MKCoordinateRegion region = MKCoordinateRegionForMapRect([poly boundingMapRect]);
region.span.latitudeDelta *= 1.2;   // Increase span by 20% to add some margin
region.span.longitudeDelta *= 1.2;
[self.mapView setRegion:region animated:YES];
like image 166
atxe Avatar answered Feb 05 '23 07:02

atxe