2
votes

I'm using Direction API to display the routes between source and destination. I formed the URL like this

https://maps.googleapis.com/maps/api/directions/json?origin=11.030342,77.038737&destination=11.0254792,76.968749&mode=driving&alternatives=true

it is giving "multiple routes" like this

`{"routes" : 
[
{  }
{  }
{  }
]}`

but when i add the waypoints in the URL

https://maps.googleapis.com/maps/api/directions/json?origin=11.030342,77.038737&destination=11.0254792,76.968749&mode=driving&alternatives=true&waypoints=11.037647,77.037447

it is giving "single route" like this

`{
 "routes" : 
 [{ 
 "legs" : [  {  }, {  }  ]
 }]
 }`

I specified the waypoint near to the starting location, still am getting single route only.

is there any mistake in my URL or it's direction API nature ??

Anyone faced this issue??

2

2 Answers

2
votes

According to this article

Generally, only one entry in the routes array is returned for directions lookups, though the Directions service may return several routes if you pass alternatives=true.

So there is no guarantee that will get some alternative routes if you added alternatives=true

0
votes

The docs may have changed from the time this question was posted. But now (in 2021) they are clear:

waypoints:

... Waypoints alter a route by directing it through the specified location(s)...

alternatives:

... This is only available for requests without intermediate waypoints.

So, yes, if you use waypoints you will get just one route, regardless of the alternatives prop's value.

Current docs here