I want to be able to capture altitude in my Android app. I know I can use GPS for where I am, but is there any way I can derive roughly how high the phone is off the ground using a combination of sensors? If not, what is the closest estimation I can get?
Asked
Active
Viewed 1.1k times
1
-
Answered pretty decently over here: http://stackoverflow.com/questions/1995998/android-get-altitude-by-longitude-and-latitude – Mels Jan 05 '12 at 21:04
-
I'm asking as if I were in a helicopter, not on land. Though, that explains half the problem. – Ryan Hayes Jan 05 '12 at 21:18
-
Ah. In that case you really do need the 3D fix Z-axis from the GPS chip. I've seen that work on the iPhone, although it's never really accurate. It often reports my current height as some 300m above sea level while I live in the Netherlands at about 3m below sea level. Don't know about Android, maybe the SDK just discards any available alt info b/c it's too inaccurate anyway... – Mels Jan 17 '12 at 11:51
-
@Mels Thank you! I didn't know GPS chips had Z-axis available, even if they are that horrible at finding your location. :-/ – Ryan Hayes Jan 17 '12 at 16:35
1 Answers
2
If the phone has a barometric pressure sensor, you can use SensorManager.getAltitude to get the altitude based on a pressure reading. This method also requires the current pressure at sea level, which can either be obtained from local airport data (via a web service) or approximated with SensorManager.PRESSURE_STANDARD_ATMOSPHERE.
For more, see:
Android: How to use SensorManager.getAltitude(float p0, float p)?