THIS SDK ISDEPRECATED.

We rolled out a new and better SDK for you.

Routing with alternative routes

Allow your users to check different routing alternatives so they can choose the one they prefer.

Sample use case: You are preparing a road trip and you would like to see different route options so you can choose one that is both optimal for your trip and suits your road trip preferences.

In the following example you can see an implementation of alternative routes using a clickable route object. Click on the route to get its ETA and the distance between its origin and destination.

To request a route with alternatives:

1RouteDescriptor routeDescriptor = new RouteDescriptor.Builder()
2 .considerTraffic(false)
3 .build()
4
5RouteCalculationDescriptor routeCalculationDescriptor = new RouteCalculationDescriptor.Builder()
6 .routeDescription(routeDescriptor)
7 .maxAlternatives(maxAlternatives)
8 .reportType(ReportType.EFFECTIVE_SETTINGS)
9 .instructionType(InstructionsType.TEXT)
10 .build();
11
12RouteSpecification routeSpecification = new RouteSpecification.Builder(
13 routeConfig.getOrigin(),
14 routeConfig.getDestination()
15)
16 .routeCalculationDescriptor(routeCalculationDescriptor)
17 .build();
1val routeDescriptor = RouteDescriptor.Builder()
2 .considerTraffic(false)
3 .build()
4
5val routeCalculationDescriptor = RouteCalculationDescriptor.Builder()
6 .routeDescription(routeDescriptor)
7 .maxAlternatives(maxAlternatives)
8 .build()
9
10val routeSpecification = RouteSpecification.Builder(origin, destination)
11 .routeCalculationDescriptor(routeCalculationDescriptor)
12 .build()

image

One alternative route

image

Three alternative routes

image

Five alternative routes