在 Android 手机中计算与 GPS 距离的最佳方法是啥?

Posted

技术标签:

【中文标题】在 Android 手机中计算与 GPS 距离的最佳方法是啥?【英文标题】:What is the best way to calculate distance from GPS in Android Phone?在 Android 手机中计算与 GPS 距离的最佳方法是什么? 【发布时间】:2017-05-27 04:11:22 【问题描述】:

我正在开发一个应用程序,该应用程序每 60 秒捕获一次用户的纬度和经度,并计算用户行进的距离。 有时我的手机在同一个位置超过一小时,但 GPS 跳到不同的位置,导致距离计算错误。

如何减少gps跳动,提高距离精度?

【问题讨论】:

GPS 跳跃取决于您手机使用的 GPS 天线的质量。这意味着,更好的手机将是它的 GPS 天线,因此更好的准确性。否则,您可以使用一些逻辑来计算距离,但这会耽误您的时间。 【参考方案1】:

GPS 的准确性在整个会话期间不会保持一致。但有办法克服这一点。即使用户没有改变位置,纬度,经度值仍然会在连续的时期内有所不同。查看以下方式如何修改这些异常。

// for location updates
private int locationupdate = 8000; //in milliseconds
private int locationdistance = 10; // in meters

在创建位置请求时,请根据您的要求提及setSmallestDisplacementsetInterval,如下所示

protected void createLocationRequest() 
    locationRequest = new LocationRequest();
    locationRequest.setInterval(locationupdate); //in milliseconds
    locationRequest.setFastestInterval(5000); //in milliseconds
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setSmallestDisplacement(locationdistance);

查看this link了解更多信息

【讨论】:

【参考方案2】:

你必须检查位置的准确性,如果不够好,请不要使用它。

can't find the exact current location in android

【讨论】:

以上是关于在 Android 手机中计算与 GPS 距离的最佳方法是啥?的主要内容,如果未能解决你的问题,请参考以下文章

计算 n 个 GPS 点之间的最短距离

GPS 使用 GeoUtils 库计算距离在印度运行良好,但在美国对 android 不起作用

android 版百度地图如何通过定位功能获得当前的位置所在的城市?

在android中使用gps安全定位

计算从一个 GPS 坐标到另一个坐标的距离?

基于与给定点的距离的最近 GPS 坐标