There is a MKMapRectUnion
function which accepts two MKMapRects
so you could first convert each MKCoordinateRegion
to an MKMapRect
and then call that function (and convert the result back to an MKCoordinateRegion
using the MKCoordinateRegionForMapRect
function).
The conversion method might look like this:
- (MKMapRect)mapRectForCoordinateRegion:(MKCoordinateRegion)coordinateRegion
{
CLLocationCoordinate2D topLeftCoordinate =
CLLocationCoordinate2DMake(coordinateRegion.center.latitude
+ (coordinateRegion.span.latitudeDelta/2.0),
coordinateRegion.center.longitude
- (coordinateRegion.span.longitudeDelta/2.0));
MKMapPoint topLeftMapPoint = MKMapPointForCoordinate(topLeftCoordinate);
CLLocationCoordinate2D bottomRightCoordinate =
CLLocationCoordinate2DMake(coordinateRegion.center.latitude
- (coordinateRegion.span.latitudeDelta/2.0),
coordinateRegion.center.longitude
+ (coordinateRegion.span.longitudeDelta/2.0));
MKMapPoint bottomRightMapPoint = MKMapPointForCoordinate(bottomRightCoordinate);
MKMapRect mapRect = MKMapRectMake(topLeftMapPoint.x,
topLeftMapPoint.y,
fabs(bottomRightMapPoint.x-topLeftMapPoint.x),
fabs(bottomRightMapPoint.y-topLeftMapPoint.y));
return mapRect;
}
Then, to actually do the union:
MKCoordinateRegion region1 = ...
MKCoordinateRegion region2 = ...
MKMapRect mapRect1 = [self mapRectForCoordinateRegion:region1];
MKMapRect mapRect2 = [self mapRectForCoordinateRegion:region2];
MKMapRect mapRectUnion = MKMapRectUnion(mapRect1, mapRect2);
MKCoordinateRegion regionUnion = MKCoordinateRegionForMapRect(mapRectUnion);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…