Android - getAltitude只返回整数

时间:2015-12-04 22:18:58

标签: android gps location altitude

我已经使用谷歌API实现了一个使用GPS的应用程序。 据我阅读文档,Location.getAltitude返回一个double,但我得到的所有值都是整数。

我希望该值至少有1位小数。

我做错了什么,或者预计会出现这样的行为?

以下是我的代码的相关部分:

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

1 个答案:

答案 0 :(得分:1)

你没有做错任何事,它并不准确。 GPS甚至不能给你1米的精度,更不用说十分之一米。