Batch routing
Allow your users to send multiple synchronous routing requests with Batch Routing components. You can mix different types of routing requests to easily compare them.
Batch Routing components as described use the Batch Routing API so you can find all details about it in the service documentation.
Sample use case: You are preparing for a trip and you would like to choose the most optimal route for your travel. You would like to compare the ETA and distances for routes depending on travel modes, route types, or avoids.
Also, you can adjust the batch request with other parameters as described in the Batch Routing API or the JavaDocs of this SDK under the API reference section.
The following example shows multiple routes requested in the batch. Each example sends three requests in one batch. All examples allow a user to compare routes visually on the map, their ETAs, and distances by clicking a chosen route.
- Travel mode example shows three routes: the route by car, the route by truck, and the route as a pedestrian.
- Route type example shows three routes: the fastest route, the shortest route, and the most eco route.
- Avoids example shows three routes: the avoid-motorways route, the avoid-ferries route, and the avoid-toll roads.
Use the following code sample to implement a similar use case.
To obtain a batch routes plan create a BatchRoutesSpecification
:
and pass it to the Routing API:
The result can be observed with a listener or through a synchronous call:
1/**2 * Callback which informs about a received [BatchRoutesPlan] or respective error.3 */4@PublicPreview(byTheEndOf = "2021.06")5@Keep6interface BatchRoutesCallback {7 /**8 * Called when a [BatchRoutesPlan] has been successfully obtained.9 *10 * @param routePlan The planned routes.11 */12 @PublicPreview(byTheEndOf = "2021.06")13 fun onSuccess(routePlan: BatchRoutesPlan)1415 /**16 * Called when an error occurs during the process of obtaining the [BatchRoutesPlan].17 *18 * @param error Error which occurred while obtaining the [BatchRoutesPlan].19 */20 @PublicPreview(byTheEndOf = "2021.06")21 fun onError(error: RoutingException)22}
Travel modes: car, truck, pedestrian | Route type: fastest, shortest, eco |
Avoids: motorways, ferries, toll roads |
You can select a route and get information about ETA and distances.
Sample use case: You are preparing the trip for the weekend and you want to check how far you can get by electric car, electric car with time budget, and non-electric car.
To achieve this you first have to create a specification and pass a list
of ReachableRangeSpecifications
:
1new BatchRoutesSpecification.Builder()2 .reachableRangeSpecifications(batchRoutesSpecifications)3 .build();
Secondly, pass the created specification to the Routing API:
getRoutePlannerAPI().planRoutes(batchRoutesSpecification, batchRoutesCallback);
This example shows how Reachable Range calculations for multiple vehicle types and time budgets can be retrieved with a single request to the Batch Routing service. For each vehicle type, you can see how its type and time budget will affect ranges returned as a result. These ranges are then visualised as polylines on the map. You can obtain the description of each reachable range by clicking the polylines.
Three possible reachable ranges from Amsterdam by electric car, combustion, and electric car with a time budget for 2 hours |