CoreLocation的两个坐标之间的距离

isi*_*atz 18 iphone core-location

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

我怎样才能做到这一点?

Ter*_*cox 26

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

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

// Correct method
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
Run Code Online (Sandbox Code Playgroud)

CLLocation

  • 由于该方法现已弃用,因此请注意. (2认同)

Mar*_*ian 18

上一个答案中的方法已在iOS 3.2中弃用.新方法非常相似

- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
Run Code Online (Sandbox Code Playgroud)

它还返回以米为单位的距离.它取决于地球的曲率.