2

I have a database with millions of lat/long pairs. I would like to implement a function to gather all lat/long pairs within a specified distance from a given lat/long pair. Is there a better way to do this than by iterating over each pair in the database and computing the distance between that pair and the given pair? I'd like to avoid brute force if I can avoid doing so!

I would like to add that I will never be searching for lat/long pairs greater than 1 mile from the given lat/long pair.

4

2 回答 2

2

许多数据库直接支持空间类型的存储,包括空间查询。这将为您正确处理距离计算,并提供一种更有效的信息提取方式。

例如,请参阅:

于 2013-06-10T18:07:50.770 回答
0

您可以做的是预先对数据库进行集群。在这种情况下,您可以将数据库划分为 3 英里的集群。然后,当您进行搜索时,您只需要比较同一集群中的点。

于 2013-06-10T18:27:03.643 回答