0

我正在开发一个基于 GPS 计算距离的移动应用程序。我正在使用以下 hasrsine 函数来计算距离。

var R = 6371; // Radius of the earth in km
      var dLat = deg2rad(lat2-lat1);  // deg2rad below
      var dLon = deg2rad(lon2-lon1); 
      var a = 
        Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * 
        Math.sin(dLon/2) * Math.sin(dLon/2); 
      var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
      var d = R * c; // Distance in km

我关心的是如何处理不同的位置精度值。

即,首先我得到一个精度为 30m 的位置,然后我得到一个精度为 150m 的位置。

为了获得更好的距离计算,我需要考虑/避免哪个位置进行距离计算?或者如何使用上述公式调整计算中的这些精度差异?

我希望得到专家的建议。

4

2 回答 2

2

任何像您这样的已知公式,或内置在您的智能手机 API 上的 API 都足够精确,可以计算 GPS 位置到下一个位置距离的小距离。

但主要的不是距离公式。
您需要过滤 GPS 位置,不应简单地计算从一个位置到下一个位置的距离。

否则,特别是在低速运动时,您将总结出一条不准确的 GPS 轨迹曲折线。

于 2013-08-13T09:44:59.140 回答
1

Generally speaking it's not that easy.. As being mentioned in comment 'distance' in that respect can be a lot of different things depending on what your coordinates are. There are several Earth elliptical 'models' so you should consider this then writing your algorithm.

In case of GPS it's WGS84 projection. if you need fast and efficient solution take a look on Proj4 library which incorporate all this things inside itself and has bindings to almost everything.

Best way to go is to convert your coordinated into meters (but then you should take zone in consideration) and then make a calculation using rectangular coordinates. you might want to have a look in here. It proposes several ways of solving it.

inaccurate, but will do a job on non extreme locations and small distance. (never use it any any proper navigation software), but..

10001.965729km = 90 degrees
1km = 90/10001.965729 degrees = 0.0089982311916 degrees
10km = 0.089982311915998 degrees
于 2013-08-13T09:09:15.550 回答