首页 > 解决方案 > 找到离给定位置最近的折线索引

问题描述

如何从折线中的位置获取最近的点?我已经使用下面的代码来完成我的工作

点击这里查看代码

但它给了我这样的输出:

List<LatLng> points = new ArrayList<>();
points.add(new LatLng(2, 2));
points.add(new LatLng(4, 2));
points.add(new LatLng(4, 4));
points.add(new LatLng(2, 4));
points.add(new LatLng(2, 2));

LatLng testPoint = new LatLng(3, 0);

LatLng nearestPoint = findNearestPoint(testPoint, points);
Log.e("NEAREST POINT: ", "" + nearestPoint); // lat/lng: (3.0,2.0)

但是我想要最接近给定点的折线的索引(包含折线列表的ArrayList),我尝试了很多方法,但没有一个成功。

如果您有解决方案,请告诉我。

标签: androidgoogle-mapsmapspolyline

解决方案


推荐阅读