开发者

iPhone - Defining a MKMapRect with 2 MKMapPoint

开发者 https://www.devze.com 2023-03-31 03:45 出处:网络
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 righ

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号