I am writing a watch-face which displays the altitude. The altitude is calculated with SensorManager.getAltitude(seaLevelPressure, currentPresure)
.
But in order to initialize this I need the pressure at sea level. Unfortunately there is no SensorManager.getSeaLevelPressure(currentPressure,currentAltitude)
.
For doing so I found the following formula (see http://rechneronline.de/barometer/ )
private float calcSeaPressure(float pressure, int altitude) {
float temperature = 9 + 273.15f;
float tempGradient = 0.0065f;
float v3 = temperature + tempGradient * altitude;
float sealevelPressure = (float) (pressure / Math.pow((1 - tempGradient * altitude / v3), .03416f / tempGradient));
sealevelPressure = (float) Math.round(sealevelPressure * 100) / 100;
return sealevelPressure;
}
But it seems that this algorithm and the one used in SensorManager.getAltitude do not fit good together. If I do:
public void setCurrentAltitude(int currentAltitude) {
sealLevelPressure = calcSealevel(currentAltitude,currentPresure);
altitude = SensorManager.getAltitude(seaLevelPressure, currentPresure)
}
The calculated altitude is different to the given currentAltitude. For small values (<1000m) the difference is acceptable. But for example 4000m the difference is 250m, which is no longer acceptable.
Now my question: How do I have to calculate the sealevel, so that setCurrentAltitude() does not report different values?
Or do you know about other Java Classes which can be used for this? Keep in mind, the values should be calculated!
Thanks