Android 14 AltitudeConverter
Native Geoid Support
Historically, Android only provided getAltitude() as WGS84 Ellipsoid height. Developers were forced to bundle massive binary grids (like EGM96) to calculate MSL altitude manually.
The API 34 Revolution
Android 14 (API Level 34) introduced the android.location.altitude package, specifically the AltitudeConverter class.
How it Works
The system now maintains a shared, high-resolution Geoid model. Apps can simply request an MSL conversion without doing the heavy lifting.
- S2 Geometry: The converter uses Google's S2 Geometry library to index the earth. It calculates the S2 Cell ID for the current latitude/longitude.
- Bilinear Interpolation: It retrieves the geoid height (N-value) for the four corners of the S2 map square containing the user. It then performs bilinear interpolation to calculate the precise offset for the specific location.
- Correction: It subtracts this offset from the WGS84 altitude:
MSL = WGS84 - Offset
Implementation
- Method:
addMslAltitudeToLocation(Context context, Location location) - Result: It injects the MSL altitude into the
Locationobject (accessible viagetMslAltitudeMeters()in API 34+). - Source Reference: See
AltitudeConverter.javain AOSP.
Why This Matters for Drones
- Accuracy: The S2-based interpolation is smoother than standard grid lookups, preventing "steps" in altitude as you fly across grid boundaries.
- Efficiency: It offloads the math to the OS, saving CPU cycles in the app's critical 10Hz loop.
- Future Proofing: As magnetic models and geoids update, the OS updates them via Play Services, ensuring your drone's altitude reference stays valid without app updates.
MAVLink GPS Implementation
Our app uses a "Polyfill" strategy:
- If Android 14+: We call
AltitudeConverter. - If Android 8-13: We fall back to our internal, optimized EGM96 grid engine.
This ensures you get the best possible altitude precision regardless of your phone's age.
Source Code Reference
- AOSP Implementation:
android/location/altitude/AltitudeConverter.java