3

I found an alternative way to obtain altitude by using SensorManager but it requires two paramaters.

public static float  getAltitude  (float p0, float p)

Computes the Altitude in meters from the atmospheric pressure and the pressure at sea level.  

p0  pressure at sea level 
p   atmospheric pressure

Would you teach us on how to use it by practical example/code snippet.

UPDATES1 I found web service provider (WSP) url to obtain the p0 pressure at sea level. I have successfully get the value but don't understand the returned values.

WSP URL:http://avdata.geekpilot.net/

Here's the sample output for Tokyo International Airport (http://avdata.geekpilot.net/weather/HND)

<weather>
<ident>RJTT</ident>
<error/>
<metar>
2011/09/22 08:00
RJTT 220800Z 04019KT 9999 -SHRA FEW012 BKN025 BKN040 21/18 Q1000 NOSIG
</metar>
<taf>
2011/09/22 04:12
TAF 
      AMD TAF 
      AMD RJTT 220409Z 2204/2306 08016KT 9999 FEW030 SCT050 
      BECMG 2204/2206 05014KT 
      TEMPO 2207/2209 36018G30KT SHRA 
      BECMG 2303/2306 10008KT
</taf>
</weather>
eros
  • 4,946
  • 18
  • 53
  • 78

2 Answers2

5

try

List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_PRESSURE);
if(sensors.size() > 0) {


  sensor = sensors.get(0);
  mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);

}

 public void onAccuracyChanged(Sensor sensor, int accuracy) {
 }

 public void onSensorChanged(SensorEvent event) {
    presure = event.values[0];
 }

float altitude = getAltitude(SensorManager.PRESSURE_STANDARD_ATMOSPHERE, presure);
Michele
  • 6,126
  • 2
  • 41
  • 45
  • Got it. Implement listener to get the value for TYPE_PRESSURE sensor. How about pressure at sea level value? Any clue on how to obtain it? – eros Sep 22 '11 at 00:13
  • yeah its the constant SensorManager.PRESSURE_STANDARD_ATMOSPHERE – Michele Sep 22 '11 at 06:03
  • "The pressure at sea level must be known, usually it can be retrieved from airport databases in the vicinity. If unknown, you can use PRESSURE_STANDARD_ATMOSPHERE as an approximation, but absolute altitudes won't be accurate. " <- this statement came from the Android's Documentation. Would like to have the value from airport databases in the vicinity. Do you have hints on how to obtain it? or web service provider url that may use to retrieve it? – eros Sep 22 '11 at 08:23
  • I found Web Service Provider URL. would you check the updated post. – eros Sep 22 '11 at 08:30
2

The current barometric air pressure at sea level (QNH) is the value after the "Q" in the metar field (in hPa - hecto-Pascals). In this case 1000 hPa.

More info on TAF and METAR can be found on wikipedia.

http://en.wikipedia.org/wiki/METAR

http://en.wikipedia.org/wiki/Terminal_aerodrome_forecast

Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181