Question

I am working with GPS related app. I need to get vertical accuracy but it always gets fix 11.0000. I need it to be dynamic as lat and lng. I have used getAccuracy but it results in horizontal accuracy.

@Override
public void onLocationChanged(Location location) {
    if (location != null) {
        lat = location.getLatitude();
        lon = location.getLongitude();
        Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
        address = mailOb.getAddress(geoCoder, lat, lon);

        if (!meterFootFlag) {
            diameter = Math.round(location.getAccuracy()) + " m.";
            altitude = Math.round(location.getAltitude()) + " m.";

        } else {
            diameter = Math.round(location.getAccuracy() * 3.28084) + " ft.";
            altitude = Math.round(location.getAltitude() * 3.28084) + " ft.";
        }

        if (diameter.contains("+"))
            diameter.replace("+", "");
        else if (altitude.contains("+"))
            altitude.replace("+", "");
    } else {
        lat = 0.0;
        lon = 0.0;

        if (!meterFootFlag) {
            altitude = 0.0 + " m.";
            diameter = 0.0 + " m.";

        } else {
            altitude = 0.0 + " ft.";
            diameter = 0.0 + " ft.";
        }
    }
    mlocManager.removeUpdates(MySettings.this);
    pDialog.dismiss();
}

How can I get vertical accuracy?

Thanks in advance

Was it helpful?

Solution

Android does not provide the vertical accuracy.
Vertical accuracy usually is 2-3 times worse then horizontal accuracy.

A simple solution: use the androids accuracy for both horizontal and vertical.

advanced solution 1: find out what android uses as total accuracy (it could be a radial error of an error-sphere, including lat,long and altitude)

try to find out a conversion factor, e.g take accuracy and multiply *2,5

Another solution, look at iphone horizontal and vert accuracy, and compare to that of android. find out an average conversion factor from acc to vert acc.

Solution 3: think why you need vertical accuracy at all. why do you need that?

hints:examples from my iphone4: when iphone shows 30m hor, i have 57vert, 10hor: 15-20vert, 5 hor: 10vert

OTHER TIPS

Altitude accuracy heavily depends on core GPS accuracy, use of additional sensors as barometer and use of wifi/cell networks plus the fusion algorithms. It is NOT have a constant ratio. If u really want to get accuracy you can try the following: check variance of the signal while motionless, this will not always work as some devices will detect motionless and just repeat last output to save power. Another approach which is bit costly is to check with reference as https://developers.google.com/maps/documentation/elevation/intro so u basically take lat lon measurement with the lat lon error and check the vertical error u get assuming you are in open area.

Starting with API 26 you can use getVerticalAccuracyMeters() method

@Override
@RequiresApi(Build.VERSION_CODES.O)
public void onLocationChanged(Location location) {
    float accuracy = location.getVerticalAccuracyMeters();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top