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

前端 未结 2 1410
悲哀的现实
悲哀的现实 2020-12-17 05:30

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

public static float  getAltitude  (float p0, float p)

C         


        
相关标签:
2条回答
  • 2020-12-17 06:03

    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);
    
    0 讨论(0)
  • 2020-12-17 06:07

    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

    0 讨论(0)
提交回复
热议问题