Sorry, you need to enable JavaScript to visit this website.

Batch routing

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 Online 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 Online 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 request a batch query create a BatchRoutingQuery:

_

return BatchRoutingQueryBuilder.create()
        .withRouteQuery(getTravelModeQuery(TravelMode.CAR))
        .withRouteQuery(getTravelModeQuery(TravelMode.TRUCK))
        .withRouteQuery(getTravelModeQuery(TravelMode.PEDESTRIAN))
        .build();
val routeQuery = BatchRoutingQueryBuilder.create()
        .withRouteQuery(createRouteTravelModesQuery(TravelMode.CAR, AmsterdamToRotterdamRouteConfig()))
        .withRouteQuery(createRouteTravelModesQuery(TravelMode.TRUCK, AmsterdamToRotterdamRouteConfig()))
        .withRouteQuery(createRouteTravelModesQuery(TravelMode.PEDESTRIAN, AmsterdamToRotterdamRouteConfig()))
        .build()

 

and pass it to the Routing API:

_

Disposable subscribe = routePlannerAPI.planBatchRoute(query)
routingApi.planBatchRoute(routeQuery)

 

Setup of the common params for the Batch Routing query:

_

return RouteQueryFactory.createRouteTravelModesQuery(travelMode, getRouteConfig());
val routeQuery = RouteQueryBuilder.create(routeConfig.origin, routeConfig.destination)
        .withMaxAlternatives(MAX_ALTERNATIVES)
        .withReport(Report.EFFECTIVE_SETTINGS)
        .withInstructionsType(InstructionsType.TEXT)
        .withTravelMode(travelMode)
        .withConsiderTraffic(false)
        .build()

 

The result can be observed with a listener or by rx java subscription:

/**
 * The listener for response of the query sent to Batch Routing online service.
 */
public interface BatchableRoutingResultListener {

    /**
     * Triggered when the response from the batch routing online service will be available.
     *
     * @param response - The information returned is a container for all route results.
     */
    void onBatchResult(BatchRoutingResponse response);

    /**
     * Triggered when the online request for batch routing failed.
     *
     * @param exception the exception returned when the request to service fails.
     */
    void onBatchError(ServiceException exception);
}
image

Travel modes: car, truck, pedestrian

image

Route type: fastest, shortest, eco

image

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 compound query:

BatchRoutingQueryBuilder.create()
        .withReachableRangeQuery(factory.createReachableRangeQueryForElectric())
        .withReachableRangeQuery(factory.createReachableRangeQueryForCombustion())
        .withReachableRangeQuery(factory.createReachableRangeQueryForElectricLimitTo2Hours())
        .build();

Secondly, pass the created query to the routing api:

Disposable subscribe = getRoutePlannerAPI().planBatchRoute(query)
        .subscribeOn(getWorkingScheduler())
        .observeOn(getResultScheduler())
        .subscribe(
                batchRoutingResponse -> displayRouteAndSetDescription(batchRoutingResponse),
                throwable -> proceedWithError(throwable.getMessage()));

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.

image

Three possible reachable ranges from Amsterdam by electric car, combustion, and electric car with a time budget for 2 hours

You are here