Android - 仅获取高度 return 整数

Android - getAltitude only return integer numbers

我实现了一个使用 GPS 的应用,google API。 据我阅读文档,Location.getAltitude returns 是双精度数,但我得到的所有值都是整数。

我想要至少保留一位小数的值。

我是不是做错了什么,或者它应该表现得像那样?

这是我的代码的相关部分:

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
        );

发送的高度总是xyz.0,比如920.0 921.0 1011.0,从来不是920.6或921.2总是.0

你没有做错任何事,只是不够准确。 GPS 连 1 米的精度都达不到,更不用说十分之一米了。