Android: How to use SensorManager.getAltitude(float p0, float p)?

早过忘川 提交于 2019-12-29 06:30:15

问题


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>

回答1:


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);



回答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



来源:https://stackoverflow.com/questions/7411114/android-how-to-use-sensormanager-getaltitudefloat-p0-float-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!