将纬度和经度转换为米或公里
我有两个 MapKit 注释,显示纬度和经度。
我有什么方法可以通过现有的 Objective-C iOS API 函数来计算两者之间的距离吗?
I have two MapKit annotations, displaying latitude and longitude.
Is there any way for me, through existing Objective-C iOS API functions to calculate the distance between the two?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
MapKit框架包含很多函数,你会发现
CLLocationDistance MKMetersBetweenMapPoints(MKMapPoint a, MKMapPoint b);
返回地图中两点之间的距离(以米为单位)。也许你可以用它来解决你的问题。首先创建两个对应点,并获取距离:
The MapKit framework contains many functions, and you will find
CLLocationDistance MKMetersBetweenMapPoints(MKMapPoint a, MKMapPoint b);
which returns the distance, in meters, between two points in the map. Maybe you could use it to solve your problem.First create the two corresponding points, and the get the distance:
CLLocation
distanceFromLocation
完成这项工作。它给出了两个 CLLocation 之间的大圆距离(以米为单位)。
我刚刚尝试并测试了它。
祝你好运!
CLLocation
distanceFromLocation
does the job.It gives the greatcircle distance in meters between two
CLLocation
s.I just tried and tested it.
Good luck!
您需要的是半正弦论坛:http://www.movable-type。 co.uk/scripts/latlong.html
来自:http://en.wikipedia.org/wiki/Haversine_formula
您可以在此处找到 Objective-C 实现: http://www.jaimerios.com/?p=39
What you need is the haversine forumla: http://www.movable-type.co.uk/scripts/latlong.html
From: http://en.wikipedia.org/wiki/Haversine_formula
You can find an Objective-C implementation here: http://www.jaimerios.com/?p=39
这称为“大圆距离”。
http://en.wikipedia.org/wiki/Great-circle_distance
This is called "great circle distance".
http://en.wikipedia.org/wiki/Great-circle_distance