I need to calculate the distance (in meters and miles) between two coordinates given
我需要计算两个给定坐标之间的距离(以米和英里为单位)
How can I do that?
我怎么做呢?
4 个解决方案
#1
26
Returns the distance (in meters) from the receiver’s coordinate to the coordinate of the specified location.
返回从接收器坐标到指定位置坐标的距离(以米为单位)。
// Deprecated in iOS 3.2 method
- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location
// Correct method
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
CLLocation
#2
18
The method in the previous answer has been deprecated in iOS 3.2. The new method is the very similar
之前答案中的方法在ios3.2中已经被弃用。新方法非常相似
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
which also returns a distance in meters. It's accounting for the curvature of the earth.
它也以米为单位返回。它解释了地球的曲率。
#3
0
swift 3 func distance(from location: CLLocation) -> CLLocationDistance Description Returns the distance (measured in meters) from the receiver’s location to the specified location. This method measures the distance between the two locations by tracing a line between them that follows the curvature of the Earth. The resulting arc is a smooth curve and does not take into account specific altitude changes between the two locations. Parameters
location The other location. Returns The distance (in meters) between the two locations. SDKs iOS 3.2+, macOS 10.6+, tvOS 9.0+, watchOS 2.0+ Declared In Core Location More Method Reference
swift 3 func距离(从位置:CLLocation) -> CLLocationDistance描述返回从接收者位置到指定位置的距离(以米为单位)。这种方法通过跟踪两个位置之间的一条线来测量它们之间的距离,这条线遵循地球的曲率。所得到的弧线是光滑的曲线,不考虑两个位置之间的具体高度变化。参数定位另一个位置。返回两个位置之间的距离(以米为单位)。SDKs iOS 3.2+、macOS 10.6+、tvos9.0 +、watchOS 2.0+在核心位置声明更多方法参考
e.g.
如。
let distance = location.distance(from: CLLocation(latitude:
CLLocationDegrees(oldLocationLat), longitude:
CLLocationDegrees(oldLocationLng)))
#4
0
swift 3
斯威夫特3
func distance(from location: CLLocation) -> CLLocationDistance Description
Returns the distance (measured in meters)
返回距离(以米为单位)
e.g.
如。
locations: [CLLocation]
let location: CLLocation = locations.last!
let distance = location.distance(from: CLLocation(latitude: CLLocationDegrees(oldLocationLat), longitude: CLLocationDegrees(oldLocationLng)))
#1
26
Returns the distance (in meters) from the receiver’s coordinate to the coordinate of the specified location.
返回从接收器坐标到指定位置坐标的距离(以米为单位)。
// Deprecated in iOS 3.2 method
- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location
// Correct method
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
CLLocation
#2
18
The method in the previous answer has been deprecated in iOS 3.2. The new method is the very similar
之前答案中的方法在ios3.2中已经被弃用。新方法非常相似
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
which also returns a distance in meters. It's accounting for the curvature of the earth.
它也以米为单位返回。它解释了地球的曲率。
#3
0
swift 3 func distance(from location: CLLocation) -> CLLocationDistance Description Returns the distance (measured in meters) from the receiver’s location to the specified location. This method measures the distance between the two locations by tracing a line between them that follows the curvature of the Earth. The resulting arc is a smooth curve and does not take into account specific altitude changes between the two locations. Parameters
location The other location. Returns The distance (in meters) between the two locations. SDKs iOS 3.2+, macOS 10.6+, tvOS 9.0+, watchOS 2.0+ Declared In Core Location More Method Reference
swift 3 func距离(从位置:CLLocation) -> CLLocationDistance描述返回从接收者位置到指定位置的距离(以米为单位)。这种方法通过跟踪两个位置之间的一条线来测量它们之间的距离,这条线遵循地球的曲率。所得到的弧线是光滑的曲线,不考虑两个位置之间的具体高度变化。参数定位另一个位置。返回两个位置之间的距离(以米为单位)。SDKs iOS 3.2+、macOS 10.6+、tvos9.0 +、watchOS 2.0+在核心位置声明更多方法参考
e.g.
如。
let distance = location.distance(from: CLLocation(latitude:
CLLocationDegrees(oldLocationLat), longitude:
CLLocationDegrees(oldLocationLng)))
#4
0
swift 3
斯威夫特3
func distance(from location: CLLocation) -> CLLocationDistance Description
Returns the distance (measured in meters)
返回距离(以米为单位)
e.g.
如。
locations: [CLLocation]
let location: CLLocation = locations.last!
let distance = location.distance(from: CLLocation(latitude: CLLocationDegrees(oldLocationLat), longitude: CLLocationDegrees(oldLocationLng)))