我需要计算两个坐标之间的距离(以米和英里为单位)
我该怎么做?
答案 0 :(得分:26)
返回从接收器坐标到指定位置坐标的距离(以米为单位)。
// Deprecated in iOS 3.2 method
- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location
// Correct method
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
答案 1 :(得分:18)
上一个答案中的方法是deprecated in iOS 3.2。新方法非常相似
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
也返回以米为单位的距离。它取决于地球的曲率。
答案 2 :(得分:0)
e.g。
let distance = location.distance(from: CLLocation(latitude:
CLLocationDegrees(oldLocationLat), longitude:
CLLocationDegrees(oldLocationLng)))
答案 3 :(得分:0)
swift 3
func distance(from location: CLLocation) -> CLLocationDistance Description
返回距离(以米为单位)
e.g。
locations: [CLLocation]
let location: CLLocation = locations.last!
let distance = location.distance(from: CLLocation(latitude: CLLocationDegrees(oldLocationLat), longitude: CLLocationDegrees(oldLocationLng)))