【发布时间】:2015-12-04 22:18:58
【问题描述】:
我已经使用谷歌 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
【问题讨论】:
-
在 Gabe 的正确答案之外,即使 GPS 有可能为您提供亚米级的高度精度,但这并不意味着 每个 Android 设备 将返回亚米精度。 Android 设备及其 GPS 无线电的质量和功能差异很大。
标签: android gps location altitude