我试图从我的压力传感器获取气压值,并从中获取高度值。这就是我尝试的方式:
@Override
public void onSensorChanged(SensorEvent event) {
// when pressure value is changed, this method will be called.
float pressure_value = 0.0f;
float height = 0.0f;
// if you use this listener as listener of only one sensor (ex, Pressure), then you don't need to check sensor type.
if( Sensor.TYPE_PRESSURE == event.sensor.getType() ) {
pressure_value = event.values[0];
System.out.println("PRESSURE" + pressure_value);
height = SensorManager.getAltitude(SensorManager.PRESSURE_STANDARD_ATMOSPHERE, pressure_value);
System.out.println("HÄÄÄÄÄÄÄÄ" + height);
tv1.setText("Druck: " + pressure_value);
tv2.setText("Höhe: " + height);
}
}
我为我的地方得到的价值是 440m。实际价值约为490米。我检查了我得到的压力已经是错误的。我该怎么做才能从传感器获得准确的值?