Ellipsoidal Altitude is always zero

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?

Answered by endecotp in 804613022

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

Accepted Answer

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

I see, this makes sense for the way it is implemented, too. i just thought it was strange at first as I was retrieving Apple Watch made routes and i expected that variable to be populated since GPS trackers usually hand out ellipsoidal, not geoid altitudes.

Thank you for the library suggestion, very helpful!

Ellipsoidal Altitude is always zero
 
 
Q