0

I have a list of point of interests from which I need to select only the x closest ones from my point of origin.

I used the google distance matrix api in order to compute the walking time required to travel from the origin to each destinations. I did the sorting inside the callback function, since the result is only available inside this scope. This works just fine. The inputs are two arrays : one storing the coordinates of the origin and the other the coordinates of each destination.

Here is my problem : I want to do the same thing, but regarding the travel time using the transit system. I can't use the distance matrix api since it doesn't accept transit as a travel method. Instead, I used the Direction service api. But in that case, the function only accepts 1 origin and 1 destination, so I can't compute the comparison between each route from within the function. But again, I can't access the results outside this scope before they are being integrated on my webpage.

Any piece of advice would be much appreciated !

Alexis Matelin
  • 194
  • 1
  • 9
  • 1
    This is definitely possible. I would create a data structure that stores the travel time for every possible permutation of origin/destination. You can attach a `google.maps.DirectionsService()` instance to each origin/destination pair. The callback to the `directionsService.route()` call for each instance would then set the travel time for that particular origin/destination pair, and fire an event to notify any observers that a new pair has been calculated. Observers could do things like update a progress bar until all pairs have been calculated, at which time the result is shown. – Steve Jansen Jan 31 '14 at 01:09
  • Sorry, I might learn something here: what exactly is the *TRANSIT* travel mode? – MrUpsidown Jan 31 '14 at 09:25
  • @MrUpsidown: it uses public transit routes mostly (like bus, train...). Check [Direction Services](https://developers.google.com/maps/documentation/javascript/directions). – Anto Jurković Jan 31 '14 at 10:27

0 Answers0