简体   繁体   English

如何在地图上找到任意点最近的位置?

[英]How can I find the closest location on a map to an arbitrary point?

Note: For the remainder of this question I will call this arbitrary point as "myPoint" to avoid confusion. 注意:对于此问题的其余部分,我将将此任意点称为“ myPoint”,以避免造成混淆。

Problem: There are several points on the map (it not practical to calculate the distance between each point and myPoint). 问题:地图上有几个点(计算每个点与myPoint之间的距离不切实际)。

Attempt at a Solution: I tried doing a radius search but in order to know where these points are located within the circle, I would have to go through all the points and make sure the distance between them is less than the search circle's radius. 尝试解决方案:我尝试进行半径搜索,但是为了知道这些点在圆内的位置,我必须遍历所有点,并确保它们之间的距离小于搜索圆的半径。

Question: How can I find the closest point to myPoint in an efficient way? 问题:如何有效地找到最接近myPoint的点? Please ask questions if clarification is needed. 请问问题是否需要澄清。

Calculating the distance between the points is inevitable. 计算点之间的距离是不可避免的。 What I suggest you can do is to slice the map in smaller pieces (not necessarily regular) and then only calculate the distance between the points that lie in the same slice. 我建议您可以做的是将地图切成小块(不一定是规则的),然后只计算同一切片中的点之间的距离。

You could use a technique to "partition" the search space (ie, the map). 您可以使用一种技术来“划分”搜索空间(即地图)。

You could consider defining a regular grid that covers the map and store all map locations within each cell of the grid. 您可以考虑定义一个覆盖地图的常规网格,并将所有地图位置存储在网格的每个单元格中。

With this it is easy to calculate/determine which cell contains the myPoint . 这样,很容易计算/确定哪个单元格包含myPoint Then it is just a matter of considering the points within the same cell. 然后,只需考虑同一单元内的点即可。

Note: You may have to consider neighboring cells too in the event the cell containing myPoint doesn't have any map locations or that the distance to a point in a neighboring cell is shorter than the distance to the point within the same cell (eg, myPoint is near a cell border). 注意:如果包含myPoint的单元格没有任何地图位置,或者与相邻单元格中的点的距离比同一单元格中的点的距离短(例如, myPoint在单元格边界附近)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM