HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 如何创建一个MKMapRect给定两个点,每个指定一个纬度和经度值?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个自定义类来扩展NSObject并实现MKOverlay协议.因此,我需要实现@L_646_1@mKMapRect协议的boundingMapRect属性.为了创建@L_646_1@mKMapRect,我当然可以使用MKMapRectMake做一个.但是,我不知道如何使用这个数据创建@L_646_1@mKMapRect,它是两点,每一个都由纬度和纬度指定. MKMapRectMake的文档状态: @H_441_2@mKMapRect MKMapRectMake( double x,double y,double width,double height ); Parameters x The point along the east-West axis of the map projection to use for the origin. y The point along the north-south axis of the map projection to use for the origin. width The width of the rectangle (measured using map points). height The height of the rectangle (measured using map points). Return Value A map rectangle with the specified values. @H_944_4@经纬度值我必须指出MKMapRect是:

24.7433195,-124.7844079
49.3457868,-66.9513812
@H_944_4@因此,目标MKMapRect需要指定一个如下所示的区域:

@H_944_4@所以,要重申一下,如何使用我的lat / lon值创建@L_646_1@mKMapRect,我可以设置为MKOverlay协议的@property(非原子,只读)MKMapRect boundingMapRect属性?提前感谢您能够提供的任何帮助!谢谢!!

解决方法

这应该做到:
// these are your two lat/long coordinates
CLLOCATIOnCoordinate2D coordinate1 = CLLOCATIOnCoordinate2DMake(lat1,long1);
CLLOCATIOnCoordinate2D coordinate2 = CLLOCATIOnCoordinate2DMake(lat2,long2);

// convert them to MKMapPoint
MKMapPoint p1 = MKMapPointForCoordinate (coordinate1);
MKMapPoint p2 = MKMapPointForCoordinate (coordinate2);

// and make a MKMapRect using mins and spans
MKMapRect mapRect = MKMapRectMake(fmin(p1.x,p2.X),fmin(p1.y,p2.y),fabs(p1.x-p2.X),fabs(p1.y-p2.y));
@H_944_4@这将使用两个x和y坐标中较小的坐标作为起始点,并计算宽度和高度两点之间的x / y跨度.

大佬总结

以上是大佬教程为你收集整理的ios – 如何创建一个MKMapRect给定两个点,每个指定一个纬度和经度值?全部内容,希望文章能够帮你解决ios – 如何创建一个MKMapRect给定两个点,每个指定一个纬度和经度值?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。