-->

与CoreLocation两个坐标之间的距离(Distance between two coordi

2019-07-04 00:33发布

我需要计算的距离(以米和英里)给出两个坐标之间

我怎样才能做到这一点?

Answer 1:

返回从接收器的距离(以米为单位)的坐标到指定位置的坐标。

// Deprecated in iOS 3.2 method
- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location

// Correct method
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location

CLLocation



Answer 2:

在以前的答案的方法已被弃用的iOS 3.2 。 这种新方法是非常相似的

- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location

这也返回米的距离。 它占地球的曲率。



Answer 3:

迅速3 FUNC距离(位置:CLLocation) - > CLLocationDistance说明返回从接收机的位置到指定位置的距离(以米为单位测得)。 此方法通过跟踪下面的地球曲率它们之间的线测量的两个位置之间的距离。 得到的弧是平滑的曲线,并没有考虑到两个位置之间的帐户特定高度变化。 参数
位置的其他位置。 返回两个位置之间的距离(以米为单位)。 iOS版的SDK 3.2+,MacOS的10.6以上,tvOS 9.0以上,watchOS 2.0+宣布核心地点更多方法参考

let distance = location.distance(from: CLLocation(latitude: 
CLLocationDegrees(oldLocationLat), longitude: 
CLLocationDegrees(oldLocationLng)))


Answer 4:

SWIFT 3

func distance(from location: CLLocation) -> CLLocationDistance Description 

返回距离(以米为单位测得)

locations: [CLLocation]

let location: CLLocation = locations.last!

let distance = location.distance(from: CLLocation(latitude: CLLocationDegrees(oldLocationLat), longitude: CLLocationDegrees(oldLocationLng)))


文章来源: Distance between two coordinates with CoreLocation