5

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?

Grimxn
  • 22,115
  • 10
  • 72
  • 85
chewy
  • 8,207
  • 6
  • 42
  • 70
  • Also note you don't have to use `setRegion` (which requires converting the `MKMapRect` to `MKCoordinateRegion`). You can use `setVisibleMapRect` directly and apply padding: `[self.mapView setVisibleMapRect:poly.boundingMapRect edgePadding:UIEdgeInsetsMake(100, 100, 100, 100) animated:NO];` –  Mar 12 '14 at 02:12

1 Answers1

13

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];
atxe
  • 5,029
  • 2
  • 36
  • 50