objective c - How to make the union between two MKCoordinateRegion -
i'm trying union between 2 mkcoordinateregion. have idea on how this?
there mkmaprectunion
function accepts 2 mkmaprects
first convert each mkcoordinateregion
mkmaprect
, call function (and convert result mkcoordinateregion
using mkcoordinateregionformaprect
function).
the conversion method might 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, union:
mkcoordinateregion region1 = ... mkcoordinateregion region2 = ... mkmaprect maprect1 = [self maprectforcoordinateregion:region1]; mkmaprect maprect2 = [self maprectforcoordinateregion:region2]; mkmaprect maprectunion = mkmaprectunion(maprect1, maprect2); mkcoordinateregion regionunion = mkcoordinateregionformaprect(maprectunion);
Comments
Post a Comment