Question

I have an array of MKMapItems and I am trying to find the coordinates I can plug into the bounding region that will make the most zoomed in map that contains all the MKMapItems

Each of these map items has coordinates so with some simple calculations of bounds the 4 corners can be found. I'm looking for a function that has already been defined if it is available.

If there is not already a predefined function, any help is figuring out the appropriate span value for a given set of points would be appreciated as well!

Thanks in advance!

Was it helpful?

Solution

iOS 7 has the method:

- (void)showAnnotations:(NSArray *)annotations animated:(BOOL)animated

Give it an array of placemarks and it will change the region for you:

[self.mapView showAnnotations:placemarks animated:YES];

You can get the placemarks from the map items:

NSMutableArray *placemarks = [NSMutableArray array];
for (MKMapItem *mapItem in mapItems) {
    [placemarks addObject:mapItem.placemark];
}

OTHER TIPS

Try with below code:

MKMapRect zoomRect = MKMapRectNull;
for (EveryMapItem in MKMapItems)
{
    MKMapPoint annotationPoint = MKMapPointForCoordinate(EveryMapItem.coordinate);
    MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0.1, 0.1);
    zoomRect = MKMapRectUnion(zoomRect, pointRect);
}
[mapView setVisibleMapRect:zoomRect animated:YES];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top