我已经使用谷歌 API 实现了一个使用 GPS 的应用程序。据我阅读文档,Location.getAltitude 返回一个双精度值,但我得到的所有值都是整数。
我想要至少有 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