I've been trying to implement a feature to get the correct altitude based on the barometer sensor from Android Galaxy S5 phones. The only problem is, I don't think it is accurate. Based on http://www.whatismyelevation.com on my particular location, it shows that my altitude is around 114 meters. However, on my phone, it shows that it is 210 meters based on the barometer sensor. I am in a tall building, however, but I don't think it is 100 meters tall.
Here is my simple code:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.configure_settings);
context = getApplicationContext();
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensors = mSensorManager.getSensorList(Sensor.TYPE_PRESSURE);
if (sensors.size() > 0)
{
sensor = sensors.get(0);
mSensorManager.registerListener(this, sensor,
SensorManager.SENSOR_DELAY_NORMAL);
}
}
@Override
public void onSensorChanged(SensorEvent event)
{
float pressure = event.values[0];
altitude = String.valueOf(SensorManager.getAltitude(
SensorManager.PRESSURE_STANDARD_ATMOSPHERE, pressure));
}
Thanks!