Multiple Route returned by DirectionResult object using the Directions API

126 views
Skip to first unread message

Subodh Shah

unread,
Aug 28, 2011, 10:46:33 PM8/28/11
to google-map...@googlegroups.com
Hi,
 
I am a new be into this. What I am trying to do is show the various direction options returned by the DirectionResult object, using custom HTML. I want to show the various routes available between source and destination. Till now I get at the most 3 routes in the DirectionRoutes array within the DirectionResult. Is this the maximum number for any given source and destination, or am I doing something wrong?
 
Also whenever a waypoint is added between the route, the number of routes returned is always 1, i.e. no routes options are returned? Is this the way the API works, or have I tried very limited search request with the waypoints?
 
Thanks,
Subodh

MymsMan

unread,
Aug 29, 2011, 4:44:53 AM8/29/11
to google-map...@googlegroups.com
I too have never seen more than 3 alternate routes returned and if you add a waypoint you will only ever get one route returned.   I don't believe these limits are documented and so could change in future releases of the API.

To get around the no alternatives with waypoints restriction I call the directions service service for each leg of the route and have an array of direction rendererers.  However I have now found that it is difficult to determine which of the alternate routes the user has selected - the directions_changed event is not driven when a user selects an alternate route - only when they drag the route (which causes the other alternates to disappear)

Rossko

unread,
Aug 29, 2011, 4:59:23 AM8/29/11
to Google Maps JavaScript API v3
What would be the use case for having more than three alternative
routes from A to B?

Subodh Shah

unread,
Aug 29, 2011, 6:48:07 AM8/29/11
to google-map...@googlegroups.com
What I was trying to do was to show list of all possible options user, the more the better would be user experience. :)

Andrew Leach

unread,
Aug 29, 2011, 6:52:42 AM8/29/11
to google-map...@googlegroups.com
On 29 August 2011 11:48, Subodh Shah <subod...@gmail.com> wrote:
> What I was trying to do was to show list of all possible options user, the
> more the better would be user experience. :)

That's almost an infinite number! And it takes a lot of processing
power to work out routes, so Google impose a reasonable limit.

MymsMan

unread,
Aug 29, 2011, 6:48:52 PM8/29/11
to google-map...@googlegroups.com, andrew....@gmail.com
It is quite reasonable to limit the alternative routes to three per leg.
The problem is with providing route alternatives for multi leg routes.
Unfortunately the api is defined to return legs within routes, rather than routes with legs.
This makes the number of potential routes increase hugely.
Consider a route with 2 waypoints - 3 legs each with 3 alternative routes, the API as currently defined would have to return 27 routes to provide the combinations.
If the API had been defined as routes within legs there would only be 9 routes to be returned which is much more reasonable.

In my application - planning my tour of Ireland I currently have 13 segments each with up to three route alternative and it only take a few seconds to render
Reply all
Reply to author
Forward
0 new messages