androidgpslocationaltitude

Android - getAltitude only return integer numbers


I've implemented an app that uses GPS, with google API. As far as I read the documentation, the Location.getAltitude returns a double, but all the values I got are round integer numbers.

I wanted the value with at least 1 decimal place.

Am I doing something wrong, or is it expected to behave like that?

Here's relevant parts of my code:

protected void createLocationRequest() {
    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(UPDATE_INTERVAL);
    mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    mLocationRequest.setSmallestDisplacement(DISPLACEMENT);
}

@Override
public void onLocationChanged(Location locationRead) {

//a lot of stuff, check signal, filter wrong reading, etc...

currentLocation = locationRead;

//compare last location with current location, some calculation, etc...

//already used String.format("%.1f",currentLocation.getLongitude()).replace(",", "."),
DecimalFormat df = new DecimalFormat("#.0");

//Send information to another class
GPS.this.interfaceGPS_Activity.locationChanged(
                (currentLocation.distanceTo(lastLocation) / 1000),
                (timeSplit),
                formatter.format(dateTimeOfGPS),
                String.format("%.7f", currentLocation.getLatitude()).replace(",", "."),
                String.format("%.7f", currentLocation.getLongitude()).replace(",", "."),
                df.format(currentLocation.getAltitude()).replace(",","."),
                currentPaceForLabel
        );

The altitude sent is always xyz.0, like 920.0 921.0 1011.0, it's never 920.6 or 921.2 always .0


Solution

  • You aren't doing anything wrong, it just isn't that accurate. GPS doesn't even give you 1m of accuracy, much less tenth of a meter.