I am trying with Google maps in android studio, I want to find alternative paths from source to destination, how do I implement this part? It is showing a single route between source and destination currently
-
1Welcome to stack overflow :-) Please look at How to [Ask](http://stackoverflow.com/help/how-to-ask). This will help to get useful answers – Nisarg Jul 21 '16 at 06:52
-
2Possible to duplicate: http://stackoverflow.com/q/14710744/2078074 – Dhruv Jul 21 '16 at 06:53
1 Answers
Direction API
Direction Request without Alternate Route
https://maps.googleapis.com/maps/api/directions/json?origin=Nevada,%20USA&destination=Los+Angeles,CA&key=API_KEY
Fastest route will be given.
Result:
- Route 1
- Distance: 489 mi
- Duration: 9 hours 29 mins
Direction Request with Alternate Route
https://maps.googleapis.com/maps/api/directions/json?origin=Nevada,%20USA&destination=Los+Angeles,CA&alternatives=true&key=API_KEY
Each route will be under "legs".
Each element in the legs array specifies a single leg of the journey from the origin to the destination in the calculated route. For routes that contain no waypoints, the route will consist of a single "leg," but for routes that define one or more waypoints, the route will consist of one or more legs, corresponding to the specific legs of the journey.
Result:
- Route 1
- Distance: 489 mi
- Duration: 9 hours 29 mins
- Route 2
- Distance: 475 mi
- Duration: 9 hours 36 mins
- Route 3
- Distance: 511 mi
- Duration: 9 hours 39 mins
Here is a screenshot of the google maps with the same request.
Note: The duration may not be the same for the web Google Maps and Direction API. There will still be about few minutes of difference. API key must be a SERVER KEY.
Here is a tutorial for implementation.
Hope this helps!

- 6,703
- 2
- 16
- 91