Search code examples
androidgoogle-mapsgoogle-directions-api

Change route option in Google Directions API for Android


I am using Google Directions API for an Android app to show a route. I know that I can get alternatives routes if I add &alternatives=true to my query URL.

But is it possible to query a route with these options from Google Maps:

enter image description here

Can I add something like &routes=best to my URL query?


Solution

  • As per documentation, you can only impose restrictions, which include these three parameters:

    • avoid=tolls
    • avoid=highways
    • avoid=ferries

    and their combinations as well. To add this to your request write avoid=tolls for a single param request or avoid=elem1|elem2|elem3 for a combination of parameters.

    You can however use these parameters for what you need:

    transit_routing_preference — Specifies preferences for transit routes. Using this parameter, you can bias the options returned, rather than accepting the default best route chosen by the API. This parameter may only be specified for transit directions, and only if the request includes an API key or a Google Maps API for Work client ID. The parameter supports the following arguments:

    less_walking indicates that the calculated route should prefer limited amounts of walking

    fewer_transfers indicates that the calculated route should prefer a limited number of transfers.