THIS SDK ISDEPRECATED.

We rolled out a new and better SDK for you.

Batch routing

Allow your users to send multiple synchronous routing requests with Batch Routing components. You can mix different types of routing requests to compare them in an easy way.

Batch Routing components 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 described in the Online Batch Routing API or JavaDocs of this SDK under the Api reference section.

The example below 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.

  • The Travel mode example shows three routes: The route by car, the route by truck, and the route as a pedestrian.
  • The Route type example shows three routes: The fastest route, the shortest route, and the most eco route.
  • The 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 TTBatchRouteQuery:

1let batchQuery = TTBatchRouteQueryBuilder.createRouteQuery(queryCar)
2 .add(queryTruck)
3 .add(queryPedestrain)
4 .build()
TTBatchRouteQuery *batchQuery = [[[[TTBatchRouteQueryBuilder createRouteQuery:queryCar] addRouteQuery:queryTruck] addRouteQuery:queryPedestrain] build]

and pass it to the Routing API:

1batchRoute = TTBatchRoute(key: Key.Routing)
2batchRoute.delegate = self
3batchRoute.batchRoute(with: batchQuery)
1self.batchRoute = [[TTBatchRoute alloc] initWithKey:Key.Routing];
2self.batchRoute.delegate = self;
3[self.batchRoute batchRouteWithQuery:batchQuery];

Setup of the common params for the Batch Routing query:

1let queryPedestrain = TTRouteQueryBuilder.create(withDest: TTCoordinate.ROTTERDAM(), andOrig: TTCoordinate.AMSTERDAM())
2 .withComputeBestOrder(true)
3 .withTraffic(true)
4 .withTravelMode(TTOptionTravelMode.pedestrian)
5 .build()
TTRouteQuery *queryPedestrain = [[[[[TTRouteQueryBuilder createWithDest:[TTCoordinate ROTTERDAM] andOrig:[TTCoordinate AMSTERDAM]] withComputeBestOrder:YES] withTraffic:YES] withTravelMode:TTOptionTravelModePedestrian] build];

The result can be observed with TTBatchRouteResponseDelegate:

1func batch(_: TTBatchRoute, completedWith response: TTBatchRouteResponse) {
2 response.visit(self)
3 displayRouteOverview()
4}
5func batch(_: TTBatchRoute, failedWithError responseError: TTResponseError) {
6}
7func visitRoute(_ response: TTRouteResult) {
8 let mapRoute = TTMapRoute(coordinatesData: response.routes.first!,
9 with: TTMapRouteStyle.defaultInactive(),
10 imageStart: TTMapRoute.defaultImageDeparture(),
11 imageEnd: TTMapRoute.defaultImageDestination())
12 mapRoute.extraData = response.routes.first?.summary
13 mapView.routeManager.add(mapRoute)
14 progress.hide()
15}
1- (void)batch:(TTBatchRoute *_Nonnull)route completedWithResponse:(TTBatchRouteResponse *_Nonnull)response {
2 [response visit:self];
3 UIEdgeInsets insets = UIEdgeInsetsMake(30 * UIScreen.mainScreen.scale, 10 * UIScreen.mainScreen.scale, 30 * UIScreen.mainScreen.scale, 10 * UIScreen.mainScreen.scale);
4 self.mapView.contentInset = insets;
5 [self.mapView.routeManager showAllRoutesOverview];
6}
7- (void)batch:(TTBatchRoute *_Nonnull)route failedWithError:(TTResponseError *_Nonnull)responseError {
8}
9- (void)visitRoute:(TTRouteResult *)response {
10 TTMapRoute *mapRoute = [TTMapRoute routeWithCoordinatesData:response.routes.firstObject withRouteStyle:TTMapRouteStyle.defaultInactiveStyle imageStart:TTMapRoute.defaultImageDeparture imageEnd:TTMapRoute.defaultImageDestination];
11 mapRoute.extraData = response.routes.firstObject.summary;
12 [self.mapView.routeManager addRoute:mapRoute];
13 [self.progress hide];
14}

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.