简体   繁体   English

使用 Google Maps SDK for Android 检测地理点是否在折线内

[英]Detect that a geo point is inside a Polyline using Google Maps SDK for Android

I am trying to re-route my directions on Google Maps but there is an issue with me that I am not sure when I have to re-route the route.我正在尝试在 Google 地图上重新规划路线,但我遇到了一个问题,我不确定何时必须重新规划路线。

So anyone tells me that how to detect that a geo point is inside a draw polyline or not??所以有人告诉我如何检测地理点是否在绘制折线内?

Because when that point will land outside that polyline I can easily re-route my directions.因为当那个点落在多段线之外时,我可以轻松地重新规划路线。

Thanks in advance,提前致谢,

you can do it with a support (almost official) library:您可以使用支持(几乎是官方的)库来做到这一点:

https://github.com/googlemaps/android-maps-utils https://github.com/googlemaps/android-maps-utils

You can find your method in the class com.google.maps.android.PolyUtil by using:您可以使用以下方法在类 com.google.maps.android.PolyUtil 中找到您的方法:

public static boolean isLocationOnPath(LatLng point, List<LatLng> polyline,
                                       boolean geodesic, double tolerance)

You can compute if the location is on the path.您可以计算该位置是否在路径上。 Geodesic true-false depends on your location and size of path, i'd usually set to false (since it's a route).测地线的真假取决于您的位置和路径的大小,我通常设置为假(因为它是一条路线)。 Tolerance is how many meters from the path are accepted, if you put for example 5, you'll get true if the point is within 5 meters from the path (to avoid rerouting for a single wrong point)!公差是接受距离路径多少米,如果你输入例如 5,如果该点距离路径在 5 米以内,你将得到 true(以避免为单个错误点重新路由)!

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

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