且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

算法寻找从给定的纬度经度位置有一定距离之内的所有纬度经度位置

更新时间:2023-08-30 13:24:40

首先比较纬度之间的距离。纬度的每度约69英里(111公里)分开。的范围内变化(由于地球的略椭圆形状)从68.703英里(110.567公里)在赤道到69.407(111.699公里)在两极。两个位置之间的距离将等于或小于其纬度之间的距离大。

Start by Comparing the distance between latitudes. Each degree of latitude is approximately 69 miles (111 kilometers) apart. The range varies (due to the earth's slightly ellipsoid shape) from 68.703 miles (110.567 km) at the equator to 69.407 (111.699 km) at the poles. The distance between two locations will be equal or larger than the distance between their latitudes.

请注意,这是不正确的经度 - 经度每度的长度是依赖于纬度。但是,如果你的数据是有界的一些区域(例如一个国家) - 你可以计算出最小和最大范围的经度和

Note that this is not true for longitudes - the length of each degree of longitude is dependent on the latitude. However, if your data is bounded to some area (a single country for example) - you can calculate a minimal and maximal bounds for the longitudes as well.

继续将低精度,速度快距离计算的假设球形地球。

Continue will a low-accuracy, fast distance calculation that assume spherical earth.

请参阅这里

See here

该方法计算的需求是mimimal。然而,结果是非常准确的对小的距离。

This method computational requirements are mimimal. However the result is very accurate for small distances.

然后,如果它是在一个给定的距离,更多或更少的,使用更精确的方法。

Then, if it is in a given distance, more or less, use a more accurate method.

GeographicLib 是最准确的实现我知道,但是的 可以作为很好Vincenty逆公式。

GeographicLib is the most accurate implementation I know, but Vincenty inverse formula may be used as well.

如果您使用的是RDBMS,设置纬度的主键和经度作为辅助键。查询一个纬度范围,或为一个纬度/经度范围内,如上述,然后计算出准确的距离结果集

If you are using an RDBMS, set the latitude as the primary key and the longitude as a secondary key. Query for a latitude range, or for a latitude/longitude range, as described above, then calculate the exact distances for the result set.

请注意所有的主要RDBMS中支持地理数据类型和查询的现代版本本身。

Note that modern versions of all major RDBMSs support geographical data-types and queries natively.