title: How to calculate sealevel pressure for given altitude and pressure
body: <p>I am writing a watch-face which displays the altitude. The altitude is calculated with <code>SensorManager.getAltitude(seaLevelPressure, currentPresure)</code>.</p>
  
  <p>But in order to initialize this I need the pressure at sea level. Unfortunately there is no <code>SensorManager.getSeaLevelPressure(currentPressure,currentAltitude)</code>.</p>
  
  <p>For doing so I found the following formula (see <a href="http://rechneronline.de/barometer/" rel="noreferrer">http://rechneronline.de/barometer/</a> )</p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>But it seems that this algorithm and the one used in SensorManager.getAltitude do not fit good together. If I do:</p>
  
  <pre><code>public void setCurrentAltitude(int currentAltitude) {
    sealLevelPressure = calcSealevel(currentAltitude,currentPresure);
    altitude = SensorManager.getAltitude(seaLevelPressure, currentPresure)
  }
  </code></pre>
  
  <p>The calculated altitude is different to the given currentAltitude. For small values (&lt;1000m) the difference is acceptable. But for example 4000m the difference is 250m, which is no longer acceptable.</p>
  
  <p>Now my question: How do I have to calculate the sealevel, so that setCurrentAltitude() does not report different values?</p>
  
  <p>Or do you know about other Java Classes which can be used for this?
  Keep in mind, the values should be calculated!</p>
  
  <p>Thanks</p>