寻找离给定点最近的折线段

huangapple 未分类评论54阅读模式
英文:

Finding the closest polyline to a given point

问题

我正在开发一个使用Google Maps API的安卓应用程序。

我正在寻找一种算法,可以帮助我找到距离给定点最近的折线。我有一个地图上有100个折线,并且我想找到距离给定点最近的折线。

一个示例可以在以下图片中看到,红点是位置,蓝线是一些折线。我可以访问折线上的所有点。我考虑过一些方式来利用起始点和结束点,但我不确定如何做。

寻找离给定点最近的折线段

目前,我只是在所有折线的列表中进行迭代,但这并不是很高效,我希望提高应用程序的性能。
样例代码:

  1. for (Map.Entry<String, ArrayList<List<LatLng>>> entry : map.entrySet()) {
  2. entry.getValue().stream().parallel().forEach(obj -> {
  3. boolean isonPath = PolyUtil.isLocationOnPath(currentLocation, obj, true, 100);
  4. if (isonPath) {
  5. // 如果点在路径上,则执行某些操作
  6. }
  7. });
  8. }
英文:

I'm working on an android app which uses the Google Maps API.

I'm looking for an algorithm which would help me find the closest polyline to a given point. I've a map with 100 polylines, and I would like to find the closest polyline to a given point.

An example would be in the following picture where the red dot is the location and the blue lines are some of the polylines. I have access to all the points on the polyline. I was thinking to leverage the starting and ending point somehow but I'm not sure how to.

寻找离给定点最近的折线段

At the moment I'm simply iterating over all the list of polylines, but it's not very efficient and I'm looking to improve the performance of the application
Sample code:

  1. for (Map.Entry&lt;String, ArrayList&lt;List&lt;LatLng&gt;&gt;&gt; entry : map.entrySet()) {
  2. entry.getValue().stream().parallel().forEach(obj -&gt; {
  3. boolean isonPath = PolyUtil.isLocationOnPath(currentLocation, obj, true, 100);
  4. if (isonPath) {
  5. // do something if the point is on the path
  6. }
  7. });
  8. }

huangapple
  • 本文由 发表于 2020年5月4日 23:26:07
  • 转载请务必保留本文链接:https://java.coder-hub.com/61595789.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定