Enlarge MKCoordinateRegionForMapRect For some margin
Asked Answered
M

1

6

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?

Maloney answered 11/3, 2014 at 20:24 Comment(1)
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];Interval
S
14

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];
Spadefish answered 11/3, 2014 at 22:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.