-1

I partitioned gps data points into multiple routes using Google API. I need the routes to return in a specific order, but since the API is asynchronous, the order that the routes return in is random.

Ex: I have 23 waypoints to turn into a route but google can't fit that many waypoints in one route

Route1 contains waypoints (1, 2, 3, 4, 5, 6, 7, 8) in that order
Route2 contains waypoints (9, 10, 11, 12, 13, 14, 15, 16)
Route3 contains waypoints (17, 18, 19, 20, 21, 22, 23)

I made multiple DirectionsService.route() calls using these routes, I want to receive the responses as Route1, Route2, Route3. How can I achieve this?

Monica
  • 1
  • 2
  • Please provide a [Minimal, Complete, Tested and Readable example](http://stackoverflow.com/help/mcve) that demonstrates the issue. – geocodezip Jul 19 '16 at 16:05
  • related question: [Google Maps API to get bus route](http://stackoverflow.com/questions/15315347/google-maps-api-to-get-bus-route) – geocodezip Jul 19 '16 at 16:07
  • For example, I have 4 routes instances of directionsService calls. I set the breakpoints after status==google.maps.DirectionsStatus.OK and check the instance number when the response is returned. The order should be 0,1,2,3. And the polyline drawn correctly. But sometimes this sequence is out of order. – Monica Jul 19 '16 at 16:13
  • Please, not in the comments, [edit] your question with the requested Information. – geocodezip Jul 19 '16 at 16:15

1 Answers1

0

Request the routes one by one, first Route1, in the callback of route() request Route2 and so on.

Dr.Molle
  • 116,463
  • 16
  • 195
  • 201