【发布时间】:2010-11-23 19:58:08
【问题描述】:
我需要计算给定两个坐标之间的距离(以米和英里为单位)
我该怎么做?
【问题讨论】:
标签: iphone core-location
我需要计算给定两个坐标之间的距离(以米和英里为单位)
我该怎么做?
【问题讨论】:
标签: iphone core-location
返回从接收器坐标到指定位置坐标的距离(以米为单位)。
// Deprecated in iOS 3.2 method
- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location
// Correct method
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
【讨论】:
上一个答案中的方法一直是deprecated in iOS 3.2。新方法很相似
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
它还返回以米为单位的距离。它解释了地球的曲率。
【讨论】:
迅速 3
func 距离(从位置:CLLocation)-> CLLocationDistance
描述
返回从接收器位置到指定位置的距离(以米为单位)。
该方法通过追踪它们之间的一条遵循地球曲率的线来测量两个位置之间的距离。生成的弧线是一条平滑曲线,没有考虑两个位置之间的特定高度变化。
参数
地点
另一个位置。
退货
两个位置之间的距离(以米为单位)。
SDK iOS 3.2+、macOS 10.6+、tvOS 9.0+、watchOS 2.0+
在核心位置声明
更多方法参考
例如
let distance = location.distance(from: CLLocation(latitude:
CLLocationDegrees(oldLocationLat), longitude:
CLLocationDegrees(oldLocationLng)))
【讨论】:
迅速 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)))
【讨论】: