I have lat and long of some locations in JSON. I want to spot whether these locations are present in a route shown by google maps.
Asked
Active
Viewed 39 times
-2
-
Welcome to Stack Overflow, please take a time to go through [the welcome tour](https://stackoverflow.com/tour) to know your way around here (and also to earn your first badge), read how to [create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and also check [How to Ask Good Questions](https://stackoverflow.com/help/how-to-ask) so you increase your chances to get feedback and useful answers. – Josef Adamcik Jul 20 '17 at 10:25
-
https://www.tutorialspoint.com/android/android_google_maps.htm. See this tutorial on how to place markers on maps. – sandy Jul 20 '17 at 11:21
1 Answers
0
Here are the steps I'd consider to achieve the effect you want:
Query for a
DirectionResponse
https://developers.google.com/maps/documentation/directions/intro#DirectionsResponsesFor each
polyline
of eachstep
of eachleg
, test whether your locations are close to the line. For simplicity you can also use theoverview_polyline
. Unfortunately this is not simple to do out-of-the-box using the Maps API alone. Check this thread for inspiration on a manual implementation. Find a point in a polyline which is closest to a latlngAlternatively, convert the polylines to GeoJSON, and process using a spatial library such as JSTS or Turf. E.g. the latter provides a pointOnLine function.

pscl
- 3,322
- 25
- 29
-
Just noticed that you're doing this on Android. In this case JTS https://github.com/locationtech/jts could be useful. In particular, I believe you can test for perpendicular distance to `LineSegment`s. – pscl Jul 21 '17 at 00:33