How to get barometric altitude in Android?
Asked Answered
D

2

5

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.

Dibs answered 10/5, 2014 at 13:4 Comment(0)
M
11

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.

Moniquemonism answered 12/5, 2014 at 12:37 Comment(5)
i am using SensorManager.PRESSURE_STANDARD_ATMOSPHERE as the reference and the altitude for me is coming as -50Transposition
That is not surprising. Atmospheric pressure has something line a +- 5% range with the weather which turns into a good bit of altitude. As I said calibrating it is the hard bit and it really depends on your use case what may be sensible.Moniquemonism
it's kind of funny since i put a note 10+ next to a note 4 and ran the same code and there was a difference in reading that would give 20 meter difference, that literally blew my entire use case out of the windowTransposition
So that implies that you need a calibration strategy that is not just relying on just a static value for a given location. The classical method is to know what the correct altitude is at a given point and then use that to work out the what pressure to use for the standard atmospheric pressure. Your two phones would end up with different values but once calibrated you would hope that they would track well together.Moniquemonism
yes kinda, just started taking this into consideration, appreciate the helpTransposition
A
1

The arguments are: GPS altitude (it's good to use average value calculated from array of measurements) and barometric pressure. Method returns pressure at sea level (formula from SensorManager.getAltitude(float p0, float p) in reverse).

public static float getSealevelPressure (float alt, float p)
{
    float p0 = (float) (p / Math.pow(1 - (alt/44330.0f), 5.255f));
    return p0;
}

I'm using the default value: SensorManager.PRESSURE_STANDARD_ATMOSPHERE until GPS collects 10 locks. After that, the above method is called.

Araujo answered 29/11, 2018 at 23:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.