找到CLLocationCoordinate2D点之间的距离

找到CLLocationCoordinate2D点之间的距离

本文介绍了找到CLLocationCoordinate2D点之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从文档中了解到,我们可以使用函数 distanceFromLocation:找到两个 CLLocation 点之间的距离。但我的问题是我没有CLLocation数据类型与我,我有CLLocationCoordinate2D点。那么如何找到两个CLLocationCoordinate2D点之间的距离。我看过帖子但对我没有帮助。

解决方案

您应该使用



<$ p $创建一个CLLocation对象p> - (id)initWithLatitude:(CLLocationDegrees)latitude
经度:(CLLocationDegrees)经度;

然后,您应该可以使用


$ b来计算距离$ b

  [location1 distanceFromLocation:location2]; 


I know from documentation we can find distance between two CLLocation points using the function, distanceFromLocation:. But my problem is I dont have CLLocation data type with me, I have the CLLocationCoordinate2D points. So how can I find distance between two CLLocationCoordinate2D points. I have seen the post post but not helpful for me.

解决方案

You should create an object of CLLocation using,

- (id)initWithLatitude:(CLLocationDegrees)latitude
    longitude:(CLLocationDegrees)longitude;

Then, you should be able to calculate the distance using

[location1 distanceFromLocation:location2];

这篇关于找到CLLocationCoordinate2D点之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 14:13