Direction api: check if a place falls in the route path between 2 places

前端 未结 1 346
抹茶落季
抹茶落季 2020-12-05 11:32

I am using Google Direction API to plot the route path between 2 places A and B. I am able to do this. Now, I have a requirement to check if given a place C falls in the rou

相关标签:
1条回答
  • 2020-12-05 12:29

    You can use the geometry library that (you can request with google maps by changing your script src to https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry) and use isLocationOnEdge and use the LatLng of point C and the polyline that is returned from the DirectionsService.

    https://developers.google.com/maps/documentation/javascript/geometry#isLocationOnEdge

    Then again, point C could ALWAYS be on the way between A and B if you added it as a waypoint, so determining if point C is "on the way" is actually a bit of a tricky concept - how far out of the way is too far for it to not be "on the way"?

    0 讨论(0)
提交回复
热议问题