0

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.

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,

  • 1
    Possible duplicate of [Identify if point is in the polygon](https://stackoverflow.com/questions/26014312/identify-if-point-is-in-the-polygon) – Andrii Omelchenko Dec 05 '18 at 09:55
  • Take a look at [this](https://stackoverflow.com/q/26014312/6950238) question and [that](https://stackoverflow.com/a/43096664/6950238) answer. – Andrii Omelchenko Dec 05 '18 at 09:56

1 Answers1

1

you can do it with a support (almost official) library:

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

You can find your method in the class com.google.maps.android.PolyUtil by using:

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)!

N Dorigatti
  • 3,482
  • 2
  • 22
  • 33