I can't seem to see it in the Docs description, but does anyone know if the above method takes into account the ellipsoid shape of Earth or is it based on a spherical shape?
I assume it does, I just need to know for sure!
Thanks in advance.
I can't seem to see it in the Docs description, but does anyone know if the above method takes into account the ellipsoid shape of Earth or is it based on a spherical shape?
I assume it does, I just need to know for sure!
Thanks in advance.
Yes, it seems like CLLocation.distance(from:)
does use some kind of ellipsoid earth model.
Using this Swift code
func testRadius(lat1: CLLocationDegrees, lon1: CLLocationDegrees, lat2: CLLocationDegrees, lon2: CLLocationDegrees, angularDistance: CLLocationDegrees) {
let loc1 = CLLocation(latitude: lat1, longitude: lon1)
let loc2 = CLLocation(latitude: lat2, longitude: lon2)
let angularDistanceRadians = angularDistance * .pi / 180
let meterDistance = loc2.distance(from: loc1)
let earthRadius = meterDistance / angularDistanceRadians // assumes circle!
func coordAsString(_ loc: CLLocation) -> String {
"(\(loc.coordinate.latitude), \(loc.coordinate.longitude))"
}
print(earthRadius, coordAsString(loc1), coordAsString(loc2))
}
// Meridians at longitudes 0°, 90°, 180° and -90°. Poles aren't well-behaved, thus ±89° instead of ±90°
testRadius(lat1: -89, lon1: 0, lat2: 89, lon2: 0, angularDistance: 178)
testRadius(lat1: -89, lon1: 90, lat2: 89, lon2: 90, angularDistance: 178)
testRadius(lat1: -89, lon1: 180, lat2: 89, lon2: 180, angularDistance: 178)
testRadius(lat1: -89, lon1: -90, lat2: 89, lon2: -90, angularDistance: 178)
// Equator from longitudes 0° to 180° and from 90° to -90°
testRadius(lat1: 0, lon1: 0, lat2: 0, lon2: 180, angularDistance: 180)
testRadius(lat1: 0, lon1: 90, lat2: 0, lon2: -90, angularDistance: 180)
you can test the earth's radius along some meridians and the equator. This leads:
6367088.045696135 (-89.0, 0.0) (89.0, 0.0)
6367088.045696135 (-89.0, 90.0) (89.0, 90.0)
6367088.045696135 (-89.0, 180.0) (89.0, 180.0)
6367088.045696135 (-89.0, -90.0) (89.0, -90.0)
6378137.000000001 (0.0, 0.0) (0.0, 180.0)
6378137.000000001 (0.0, 90.0) (0.0, -90.0)
so an equatorial radius of 6,378,137 m and — as we are using pi and radians here instead of the "circumference factor" specific to the ellipse's eccentricity (which we don't know) — a "mean longitudinal" radius of around 6,367,088 m.
These match the commonly used reference ellipsoid WGS-84 also used in GPS, which makes sense as CoreLocation
is the API for accessing the iPhone's GPS data.
Did you read the reference?
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.