From 04d7e83e65e246e154b5b346e3eb0081b741ae88 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Thu, 29 Jul 2010 17:59:58 -0700 Subject: [PATCH] Added SensorManager.getAltitude() this is a helper function to calculate the altitude from the pressure and pressure at sea level. Change-Id: I3f6f14fee6190388f95afa36a66287e3d59eef9b --- api/current.xml | 26 +++++++++++++ core/java/android/hardware/SensorManager.java | 37 +++++++++++++++---- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/api/current.xml b/api/current.xml index 9de160a8a9d56..4dd0909218e4f 100644 --- a/api/current.xml +++ b/api/current.xml @@ -77858,6 +77858,21 @@ deprecated="not deprecated" visibility="public" > + + + + + + + + + * Typically the atmospheric pressure is read from a + * {@link Sensor#TYPE_PRESSURE} sensor. The pressure at sea level must be + * known, usually it can be retrieved from airport databases in the + * vicinity. + *

+ * + * @param p0 pressure at sea level + * @param p atmospheric pressure + * @return Altitude in meters + */ + public static float getAltitude(float p0, float p) { + final float coef = 1.0f / 5.255f; + return 44330.0f * (1.0f - (float)Math.pow(p/p0, coef)); + } + + + /** * {@hide} */ public void onRotationChanged(int rotation) {