iPhone - Defining a MKMapRect with 2 MKMapPoint
How would you build the simpliest way a MKMapRect with 2 MKMapPoints, assuming that you don't know wh开发者_运维百科ere are those points (the first can be lower or upper, more on the left or the right, compared to the second one).
Here's one way (mp1
and mp2
are MKMapPoint
pairs of opposite corners):
MKMapRect mr = MKMapRectMake (fmin(mp1.x, mp2.x),
fmin(mp1.y, mp2.y),
fabs(mp1.x - mp2.x),
fabs(mp1.y - mp2.y));
You could also convert your points to 2 rectangles and get the union:
MKMapRect rect1 = MKMapRectMake(point1.x, point1.y, 0, 0);
MKMapRect rect2 = MKMapRectMake(point2.x, point2.y, 0, 0);
MKMapRect finalRect = MKMapRectUnion(rect1, rect2);
精彩评论