I am trying to retrieve the ellipsoidal altitude from a CLLocation but it seems like an invalid value is always returned, no matter the vertical accuracy (which according to the documentation should just be > 0) I first encountered this problem while developing a tool to retrieve workouts from healthkit, but i tried this code in a playground and i still get zero.
import CoreLocation
var location = CLLocation(coordinate: CLLocationCoordinate2D(latitude: 46.071067, longitude: 13.234579), altitude: 113, horizontalAccuracy: CLLocationAccuracy(floatLiteral: 1.0), verticalAccuracy: CLLocationAccuracy(floatLiteral: 1.0), timestamp: Date())
print(location.ellipsoidalAltitude)
Am I doing something wrong or is this a bug?
So you seem to be expecting that you can create a CLLocation
with the regular altitude
set, and then read the ellipsoidalAltitude
property, and CLLocation will do the conversion for you. Right?
I wouldn't expect it to do that. I would expect that if you get a location from the CLLocationManager
then it would have both properties populated, but I would not expect that it would do the conversion for a location that I have supplied myself. Of course the docs don't actually say what happens; maybe I'm wrong.
I recommend GeographicLib - https://geographiclib.sourceforge.io - for this sort of thing. In particular, https://geographiclib.sourceforge.io/C++/doc/geoid.html