【问题标题】:Android - getAltitude only return integer numbersAndroid - getAltitude 只返回整数
【发布时间】: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


【解决方案1】:

你没有做错什么,只是不够准确。 GPS 甚至无法提供 1m 的精度,更不用说十分之一米了。

【讨论】:

  • 谢谢加布。我不知道。我被 getAltitude 返回的“双倍”误导了。无论如何,我的问题是当我计算总海拔增益时,我想我会对这些值进行某种“平滑”,然后计算海拔增益。有时我会在较长的计划路线上得到 -1、+1 的变化,当我总结时,它会获得 100m 的增益,这是不正确的。我会做一些工作,并且,为有气压计的人实施一个替代方案......
  • 我昨天为尝试进行累积距离跟踪的人回答了类似的问题-stackoverflow.com/questions/34079118/… 基本上,要做到准确,需要做一些工作才能得到一个好的答案。
  • 您可以在带有压力传感器的手机上获得更好的累积海拔增益/损失数字,但您仍然需要应用一些过滤并努力使平坦返回零。使用某些手机 gps 芯片组,即使在非常平坦的地形上很难应对,您也可能会得到相当大的高度跳跃,例如上下 10m。在这种情况下,在线查找是最好的解决方案,通常在平坦的地形中,但在丘陵地形中则不是很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-30
  • 1970-01-01
  • 2014-02-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多