将纬度和经度转换为米或公里

发布于 2024-11-25 21:46:31 字数 87 浏览 1 评论 0原文

我有两个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

蓝梦月影 2024-12-02 21:46:31

MapKit框架包含很多函数,你会发现CLLocationDistance MKMetersBetweenMapPoints(MKMapPoint a, MKMapPoint b); 返回地图中两点之间的距离(以米为单位)。也许你可以用它来解决你的问题。

首先创建两个对应点,并获取距离:

MKMapPoint p1 = MKMapPointForCoordinate(coord1);
MKMapPoint p2 = MKMapPointForCoordinate(coord2);
CLLocationDistance dist = MKMetersBetweenMapPoints(p1, p2);

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:

MKMapPoint p1 = MKMapPointForCoordinate(coord1);
MKMapPoint p2 = MKMapPointForCoordinate(coord2);
CLLocationDistance dist = MKMetersBetweenMapPoints(p1, p2);
天暗了我发光 2024-12-02 21:46:31

CLLocation distanceFromLocation 完成这项工作。
它给出了两个 CLLocation 之间的大圆距离(以米为单位)。
我刚刚尝试并测试了它。

祝你好运!

CLLocation distanceFromLocation does the job.
It gives the greatcircle distance in meters between two CLLocations.
I just tried and tested it.

Good luck!

夜声 2024-12-02 21:46:31

您需要的是半正弦论坛:http://www.movable-type。 co.uk/scripts/latlong.html

haversine

来自: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

haversine

From: http://en.wikipedia.org/wiki/Haversine_formula

You can find an Objective-C implementation here: http://www.jaimerios.com/?p=39

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文