算法寻找从给定的纬度经度位置有一定距离之内的所有纬度经度位置 [英] Algorithm to find all Latitude Longitude locations within a certain distance from a given Lat Lng location

查看:263
本文介绍了算法寻找从给定的纬度经度位置有一定距离之内的所有纬度经度位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于与纬度+经度位置的地方的数据库,如40.8120390,-73.4889650,我将如何找到特定位置的给定距离内的所有位置?

Given a database of places with Latitude + Longitude locations, such as 40.8120390, -73.4889650, how would I find all locations within a given distance of a specific location?

这似乎并不十分有效,选择从数据库中的所有位置,然后再通过逐一,得到了距离起始位置,看他们是否在指定距离内。有没有缩小从数据库中初步选定位置的好方法吗?一旦我有(或不?),一组位置缩小,我还有一通过他们去逐一检查的距离,或有更好的办法吗?

It doesn't seem very efficient to select all locations from the DB and then go through them one by one, getting the distance from the starting location to see if they are within the specified distance. Is there a good way to narrow down the initially selected locations from the DB? Once I have (or don't?) a narrowed down set of locations, do I still go through them one by one to check the distance, or is there a better way?

我这样做的语言并不重要。谢谢!

The language I do this in doesn't really matter. Thanks!

推荐答案

首先比较纬度之间的距离。纬度的每度约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.

这篇关于算法寻找从给定的纬度经度位置有一定距离之内的所有纬度经度位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆