Search code examples
phpgoogle-maps-api-3connection-pooling

how to check whether a place is present in between a route using google maps api


hi i am developing a project on carpooling(users can offer lift and take lift to/from people) the problem can be better understood by an example


example:
suppose a person A is travelling from a place startA to endA and is ready to offer some seats in his car.then a person B is such that,his start position startB is between startA to endA and his endB may or may not be in between startA to endA.
then how to check whether startB is in between startA to endA using google maps api
I am doing my project in PHP.


Solution

  • This sounds like the "search along route" problem, to which the Google Maps APIs have no exact match, but there is an approach that may work well enough for your purpose.

    Let me assume you can delegate the calculations to the browser's JavaScript engine. Then you can request directions from startA to endA and use RouteBoxer with a threshold T1 of how far is person A willing to deviate from the original route in order to pick person B.

    With that threshold, you can build a set of bounding boxes to search along the route from startA to startB within distance T1 and check whether startB is contained by one of those boxes.

    There is also the threshold T2 of how far from endB is person B willing to be dropped, but that one you can calculate easily by requesting (in different requests) driving and/or walking directions from endA to endB. If the above (startB is within T1 from the route) is true but the distance from endA to endB is greater than T2, then you could either warn person B or drop the route altogether.

    This project sounds like a lot of fun, but let me warn you about one thing: you don't want to send requests to the Google Maps APIs (specially the Directions API) from your own server, using PHP. Not when the inputs are provided by users in real time. Instead, you should let each user's browser do the requests, using JavaScript. Otherwise, when your site grows popular it will run out of daily allowance for the service. Read the Geocoding Strategies for more.