Search code examples
javaandroidgeolocationgeoaltitude

How to get barometric altitude in Android?


What are the data needed for calculating barometric altitude? How do I get them and then calculate the altitude?

Also how accurate is the barometric compared to GPS altitude? I tried GPS but after searching hours in the web I cannot find a suitable Geoid library.

Please correct me if I got any concept long.


Solution

  • You need to use the pressure sensor to measure the pressure then use the SensorManager.getAltitude(float, float) call to convert the measures pressure along with a reference sea level pressure to get the altitude.

    The tricky bit is what to use as the reference pressure. This will change with the weather and will drift over time. Typically you would do some sort of calibration to set this values and possibly update it. It depends on your use case what the right solution is.

    If properly calibrated pressure based altitude is considerably more accurate then gps based altitude especially if want you are interested in is altitude differences rather than absolute altitudes. With a bit of filtering on the raw pressure sensor values you can easily detect holding the phone at face level or arms length above your head which you want do with gps.