javaandroidandroid-studiosensorspressure

Android getAltitude based on atmospheric pressure and sensor pressure


I'm trying to figure out how to get my current altitude based on atmospheric pressure and sensor pressure.

getAltitude(SensorManager.PRESSURE_STANDARD_ATMOSPHERE, sensorPressure);

But this doesn't seem to work as the following error appears: getAltitude (java.lang.String) in MainActivity cannot be appleid to (float, float); But I can't find any documentation on what is supposed to be in the parameters.

public float getAltitude(String apiPressure) {
        float floatPressure = Float.parseFloat(apiPressure);
       float altitude = getAltitude(SensorManager.PRESSURE_STANDARD_ATMOSPHERE, floatPressure);
        return altitude;
    }

Any help is appreciated!


Solution

  • You are calling your method getAltitude(String apiPressure) thats defined in your package. I guess you want to call getAltitude thats defined in android.hardware.SensorManager:

    SensorManager.getAltitude(SensorManager.PRESSURE_STANDARD_ATMOSPHERE,pressure)