近距离gps位置的算法

时间:2022-09-15 07:46:38

I'm looking for a good algorithm for finding a list nearest positions taking into account quality of data we receiving from gps devices.

我正在寻找一个很好的算法,用于查找最接近位置的列表,同时考虑到我们从gps设备接收的数据质量。

The problem is as follows:

问题如下:

  1. I have a position of point A. A= (LNG, LAT, ALT, HorizontalAccuracy, VerticalAccuracy)
    • HorizontalAccuracy and VerticalAccuracy it's a potencial error in meters
    • Horizo​​ntalAccuracy和VerticalAccuracy它是以米为单位的潜在误差
  2. 我有一个点A的位置.A =(LNG,LAT,ALT,Horizo​​ntalAccuracy,VerticalAccuracy)Horizo​​ntalAccuracy和VerticalAccuracy它是一个潜在的误差,以米为单位
  3. I have a list of others B = [B1, ... Bn] each Bx is (LNG, LAT, ALT, HorizontalAccuracy, VerticalAccuracy)
  4. 我有一个其他B的列表B = [B1,... Bn]每个Bx是(LNG,LAT,ALT,Horizo​​ntalAccuracy,VerticalAccuracy)
  5. I would like to find the list of points Bx nearest to A and order that list according to distance Bx and A.
  6. 我想找到最接近A的Bx点列表,并根据距离Bx和A对该列表进行排序。
  7. The order of that list should taken into account accuracy of data we have. The problem with accuracy starts when the distance between points is shorter then accuracy.
  8. 该列表的顺序应考虑到我们拥有的数据的准确性。当点之间的距离比精度更短时,精度问题就开始了。

3 个解决方案

#1


1  

Simply use the Euclidean distance:

只需使用欧几里德距离:

distance = sqrt((lng_a - lng_b)^2 + ... + (alt_a - alt_b)^2)

And then only sort by distance.

然后只按距离排序。

#2


1  

Precision: you can set a filter (ie: decide which locations you will use and which ones you will omit). In CLLocation you still get the centerpoint so there's not much of use for precision factor in a distance formula.

精度:您可以设置过滤器(即:确定您将使用哪些位置以及您将省略哪些位置)。在CLLocation中,您仍然可以获得中心点,因此在距离公式中使用精度因子的次数不多。

If you try to calculate distance between two geolocations with accuracy worse than their calculated distance between their centers that would be more of an approach problem than a mathematical problem.

如果您尝试计算两个地理位置之间的距离,其准确度比其中心之间的计算距离更差,这将是一个接近问题而不是数学问题。

Distance: you can always use CLLocation's distanceFromLocation: method. Don't use Eucledian formala to calculate distance between geolocations.

距离:您始终可以使用CLLocation的distanceFromLocation:方法。不要使用Eucledian formala来计算地理位置之间的距离。

Sorting: not much to say here. Sorting algorithms have their pros and cons. I would first try to implement one of the native sorting possibilities and optimize later if they appear to be too slow.

排序:这里不多说。排序算法有其优点和缺点。我首先尝试实现一种原生排序的可能性,如果它们看起来太慢,我会稍后进行优化。

#3


1  

First the horicontal accuracy is only an estimate, so don#t rely to much on it. However I would remove the locations that exceed a accuracy threshold.

首先,水平精度只是一个估计,所以不要太依赖它。但是,我会删除超过准确度阈值的位置。

Then if you have less than 10.000 points sort by distance.
If you have more, then use a spatial index first, like Quadtree, to speed up by avoiding to calculate the distance to all locations, but only the one nearby.

然后,如果你按距离排序少于10.000点。如果你有更多,那么首先使用空间索引,比如四叉树,通过避免计算到所有位置的距离来加速,但只有附近的距离。

Distance calculations:
That depends if your location sare spread over the wolrd, or only within 100km. If over the world, use the built in distanceTo(), if within 100km and you have many points or need a fast calculation, the use the distance formula based on equiRectangular projection, which uses only one cos() operation. The sqrt() you can ommit, since you probably can sort by sqr of the distance to.

距离计算:这取决于您的位置是否分布在wolrd上,或仅在100km内。如果在世界范围内,使用内置distanceTo(),如果在100km内并且您有许多点或需要快速计算,则使用基于equiRectangular投影的距离公式,该公式仅使用一个cos()运算。您可以省略sqrt(),因为您可能可以按距离的sqr排序。

#1


1  

Simply use the Euclidean distance:

只需使用欧几里德距离:

distance = sqrt((lng_a - lng_b)^2 + ... + (alt_a - alt_b)^2)

And then only sort by distance.

然后只按距离排序。

#2


1  

Precision: you can set a filter (ie: decide which locations you will use and which ones you will omit). In CLLocation you still get the centerpoint so there's not much of use for precision factor in a distance formula.

精度:您可以设置过滤器(即:确定您将使用哪些位置以及您将省略哪些位置)。在CLLocation中,您仍然可以获得中心点,因此在距离公式中使用精度因子的次数不多。

If you try to calculate distance between two geolocations with accuracy worse than their calculated distance between their centers that would be more of an approach problem than a mathematical problem.

如果您尝试计算两个地理位置之间的距离,其准确度比其中心之间的计算距离更差,这将是一个接近问题而不是数学问题。

Distance: you can always use CLLocation's distanceFromLocation: method. Don't use Eucledian formala to calculate distance between geolocations.

距离:您始终可以使用CLLocation的distanceFromLocation:方法。不要使用Eucledian formala来计算地理位置之间的距离。

Sorting: not much to say here. Sorting algorithms have their pros and cons. I would first try to implement one of the native sorting possibilities and optimize later if they appear to be too slow.

排序:这里不多说。排序算法有其优点和缺点。我首先尝试实现一种原生排序的可能性,如果它们看起来太慢,我会稍后进行优化。

#3


1  

First the horicontal accuracy is only an estimate, so don#t rely to much on it. However I would remove the locations that exceed a accuracy threshold.

首先,水平精度只是一个估计,所以不要太依赖它。但是,我会删除超过准确度阈值的位置。

Then if you have less than 10.000 points sort by distance.
If you have more, then use a spatial index first, like Quadtree, to speed up by avoiding to calculate the distance to all locations, but only the one nearby.

然后,如果你按距离排序少于10.000点。如果你有更多,那么首先使用空间索引,比如四叉树,通过避免计算到所有位置的距离来加速,但只有附近的距离。

Distance calculations:
That depends if your location sare spread over the wolrd, or only within 100km. If over the world, use the built in distanceTo(), if within 100km and you have many points or need a fast calculation, the use the distance formula based on equiRectangular projection, which uses only one cos() operation. The sqrt() you can ommit, since you probably can sort by sqr of the distance to.

距离计算:这取决于您的位置是否分布在wolrd上,或仅在100km内。如果在世界范围内,使用内置distanceTo(),如果在100km内并且您有许多点或需要快速计算,则使用基于equiRectangular投影的距离公式,该公式仅使用一个cos()运算。您可以省略sqrt(),因为您可能可以按距离的sqr排序。