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

Routing examples

Routing examples

Have a look at our functional examples to see how to implement search features with TomTomOnlineSDKRouting.

Speed up development by using our sample code snippets in your app. Try all of this out with the Maps SDK Examples app!

Travel modes

Allow your users to plan a route for different travel modes.

Sample use case: You want to check what travel mode (car or truck) gives you the best ETA for a trip from Amsterdam to Rotterdam.

_

let query = TTRouteQueryBuilder.create(withDest: TTCoordinate.AMSTERDAM(), andOrig: TTCoordinate.ROTTERDAM())
    .withTravelMode(.car)
    .build()
routePlanner.plan(with: query)
TTRouteQuery *query =
    [[[TTRouteQueryBuilder createWithDest:[TTCoordinate AMSTERDAM]
                                  andOrig:[TTCoordinate ROTTERDAM]]
        withTravelMode:TTOptionTravelModeCar] build];
[self.routePlanner planRouteWithQuery:query];

 



image

Travel mode car.

image

Travel mode truck.

image

Travel mode pedestrian.

Route types

Allow your users to plan a route that will be the fastest, shortest, most thrilling or greenest.

Sample use case: You plan a trip from Amsterdam to Rotterdam and want to compare ETAs for different types of routes to choose the best fit for your preferences.

We can use types like:

  • Fastest

  • Shortest

  • Easiest

_

let query = TTRouteQueryBuilder.create(withDest: TTCoordinate.AMSTERDAM(), andOrig: TTCoordinate.ROTTERDAM())
    .withRouteType(.fastest)
    .build()
routePlanner.plan(with: query)
TTRouteQuery *query =
    [[[TTRouteQueryBuilder createWithDest:[TTCoordinate AMSTERDAM]
                                  andOrig:[TTCoordinate ROTTERDAM]]
        withRouteType:TTOptionTypeRouteFastest] build];
[self.routePlanner planRouteWithQuery:query];

 



image

Route type fastest.

image

Route type shortest.

image

Route type eco.

Route avoids

Allow your users to plan a route that avoids things like toll roads, motorways, ferries, unpaved roads, carpool lanes, and roads that they have already taken.

Sample use case: You plan a trip between the TomTom offices in Amsterdam and Oslo and you would like to check
how much time you gain by taking a ferry and how much more time it will take to drive if you don’t that motorways so you can take the best route for you.

You can use parameters like:

  • tollRoads

  • motorways

  • ferries

  • unpavedRoads

  • carpools

  • alreadyUsedRoads

_

let query = TTRouteQueryBuilder.create(withDest: TTCoordinate.OSLO(), andOrig: TTCoordinate.AMSTERDAM())
    .withAvoidType(.motorways)
    .build()
routePlanner.plan(with: query)
TTRouteQuery *query =
    [[[TTRouteQueryBuilder createWithDest:[TTCoordinate OSLO]
                                  andOrig:[TTCoordinate AMSTERDAM]]
        withAvoidType:TTOptionTypeAvoidMotorways] build];
[self.routePlanner planRouteWithQuery:query];

 



image

Route avoid motorways.

image

Route avoid toll roads.

image

Route avoid ferries.

Sample use case: You plan a trip from A to B and you know that on your way there are vignettes.
Additionally, there is an area which has a very high traffic. You want to avoid both vignettes and the specified area.

To avoid vignettes:

_

let vignettesArray = ["HUN", "CZE", "SVK"]
dispatchGroup.enter()
let query2 = TTRouteQueryBuilder.create(withDest: TTCoordinate.ROMANIA(), andOrig: TTCoordinate.CZECH_REPUBLIC())
    .withTraffic(false)
    .withAvoidVignettesArray(vignettesArray)
    .build()
NSArray<NSString *> *vignettesArray = @[ @"HUN", @"CZE", @"SVK" ];
TTRouteQuery *query2 =
    [[[[TTRouteQueryBuilder createWithDest:TTCoordinate.ROMANIA
                                   andOrig:TTCoordinate.CZECH_REPUBLIC]
        withTraffic:YES] withAvoidVignettesArray:vignettesArray] build];

 

To avoid an area:

_

let boundingBox = TTLatLngBounds(seBounds: TTCoordinate.ARAD_TOP_LEFT_NEIGHBORHOOD(), nwBounds: TTCoordinate.ARAD_BOTTOM_RIGHT_NEIGHBORHOOD())
var boundingBoxArray = [boundingBox]
let query2 = TTRouteQueryBuilder.create(withDest: TTCoordinate.ROMANIA(), andOrig: TTCoordinate.CZECH_REPUBLIC())
    .withAvoidArea(&boundingBoxArray, count: UInt(boundingBoxArray.count))
    .withTraffic(true)
    .build()
TTLatLngBounds boundingBox[1];
boundingBox[0] =
    TTLatLngBoundsMake([TTCoordinate ARAD_TOP_LEFT_NEIGHBORHOOD],
                       [TTCoordinate ARAD_BOTTOM_RIGHT_NEIGHBORHOOD]);
TTRouteQuery *query2 =
    [[[[TTRouteQueryBuilder createWithDest:TTCoordinate.ROMANIA
                                   andOrig:TTCoordinate.CZECH_REPUBLIC]
        withTraffic:YES] withAvoidArea:boundingBox count:1] build];

 



image

Route no avoids.

image

Route avoid vignettes.

image

Route avoid area.

Routing with waypoints

Allow your users to plan a route with up to 50 waypoints. Help your users to get the best route through all their stops in the optimal order.

Sample use case: You plan a trip from the TomTom office in Amsterdam to the office in Berlin.
There are a few places that you would like to visit on during the drive.
You would like to check if your preferred route is the best way to visit all of the places in the shortest time.
To do this, input the coordinates as waypoints and call the routing module using the withComputeBestOrder paramater.

In the example below the route is from Amsterdam to Berlin using withComputeBestOrder parameters.

_

let query = TTRouteQueryBuilder.create(withDest: TTCoordinate.BERLIN(), andOrig: TTCoordinate.AMSTERDAM())
    .withWayPoints(&waypoints, count: UInt(waypoints.count))
    .build()
routePlanner.plan(with: query)
TTRouteQuery *query = [[[TTRouteQueryBuilder
    createWithDest:[TTCoordinate BERLIN]
           andOrig:[TTCoordinate AMSTERDAM]] withWayPoints:self.waypoints
                                                     count:3] build];
[self.routePlanner planRouteWithQuery:query];

 



image

Initial order.

image

Best order.

Departure/Arrival time

Allow your users to plan a route for a specific arrival or departure time so they can use this information to adjust their commute plans.

Sample use case: You have a busy schedule and need to plan your day carefully.
You use the arrival at option to learn when you need to leave in order to be at a specific place at a specific time.
You then use depart at to know your ETA for your next appointment.

In the example below, you can see a sample implementation using the arrive at and depart at parameters for a trip from Amsterdam to Rotterdam.
The example uses a standard date/time picker widget.

_

let query = TTRouteQueryBuilder.create(withDest: TTCoordinate.ROTTERDAM(), andOrig: TTCoordinate.AMSTERDAM())
    .withDepartAt(date)
    .build()
self.routePlanner.plan(with: query)
TTRouteQuery *query = [[[TTRouteQueryBuilder
    createWithDest:[TTCoordinate ROTTERDAM]
           andOrig:[TTCoordinate AMSTERDAM]] withDepartAt:date] build];
[weakSelf.routePlanner planRouteWithQuery:query];

 

_

let query = TTRouteQueryBuilder.create(withDest: TTCoordinate.ROTTERDAM(), andOrig: TTCoordinate.AMSTERDAM())
    .withArriveAt(date)
    .build()
self.routePlanner.plan(with: query)
TTRouteQuery *query = [[[TTRouteQueryBuilder
    createWithDest:[TTCoordinate ROTTERDAM]
           andOrig:[TTCoordinate AMSTERDAM]] withArriveAt:date] build];
[weakSelf.routePlanner planRouteWithQuery:query];

 



image

One alternative.

image

Five alternatives.

Route alternatives

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

_

let mapRoute = TTMapRoute(coordinatesData: planedRoute,
                          with: TTMapRouteStyle.defaultActive(),
                          imageStart: TTMapRoute.defaultImageDeparture(),
                          imageEnd: TTMapRoute.defaultImageDestination())
mapView.routeManager.add(mapRoute)
mapRoute.extraData = planedRoute.summary
TTMapRoute *mapRoute = [TTMapRoute
    routeWithCoordinatesData:planedRoute
              withRouteStyle:TTMapRouteStyle.defaultActiveStyle
                  imageStart:TTMapRoute.defaultImageDeparture
                    imageEnd:TTMapRoute.defaultImageDestination];
[self.mapView.routeManager addRoute:mapRoute];
mapRoute.extraData = planedRoute.summary;

 

Routing with language parameter

Allow your user to to get results in different languages so make your app international.
The language parameter determines the language of the guidance messages.
It does not affect proper nouns (the names of streets, plazas, etc.)

Sample use case: You are planning a journey and you want to have the list of
instructions in different languages.
List of the supported languages can be found
here.

To request a route using language parameter:

_

let query = TTRouteQueryBuilder.create(withDest: TTCoordinate.BERLIN(), andOrig: TTCoordinate.AMSTERDAM())
    .withInstructionsType(.text)
    .withLang(language)
    .build()
routePlanner.plan(with: query)
TTRouteQuery *query =
    [[[[TTRouteQueryBuilder createWithDest:[TTCoordinate BERLIN]
                                   andOrig:[TTCoordinate AMSTERDAM]]
        withInstructionsType:TTOptionInstructionsTypeText] withLang:language]
        build];
[self.routePlanner planRouteWithQuery:query];

 

_

func route(_: TTRoute, completedWith result: TTRouteResult) {
}
- (void)route:(TTRoute *)route completedWithResult:(TTRouteResult *)result {
}

 

Maneuver list

Serve your users with list of maneuvers (driving instructions), providing turn by turn information for every maneuver.
You can get the maneuvers in different languages to internationalize your app.

Sample use case: You are planning a journey and you want to have the list of maneuvers so you can look them up en route.

In the example below, you can see an implementation of a maneuver list that is available in English, German, Spanish and French.

_

let query = TTRouteQueryBuilder.create(withDest: TTCoordinate.BERLIN(), andOrig: TTCoordinate.AMSTERDAM())
    .withInstructionsType(.text)
    .withLang(language)
    .build()
routePlanner.plan(with: query)
TTRouteQuery *query =
    [[[[TTRouteQueryBuilder createWithDest:[TTCoordinate BERLIN]
                                   andOrig:[TTCoordinate AMSTERDAM]]
        withInstructionsType:TTOptionInstructionsTypeText] withLang:language]
        build];
[self.routePlanner planRouteWithQuery:query];

 



image

Maneuver list English.

image

Maneuver list Spanish.

Consumption Model

Allow your user to utilise the vehicle-specific consumption model when requesting a new route.
The consumption model can be calculated based on a number of Routing API API
parameters for two vehicle types: combustion or electric and the output will
contain the additional field fuelConsumptionInLiters or batteryConsumptionInkWh.
For more details, please refer to: Consumtion models documentation.

Sample use case: You are planning a journey and you want to select the most optimal route
in terms of fuel / energy consumption.

To request a route and calculate the consumption model for a combustion vehicle:

_

style = ETAView.ETAViewStyle.consumptionLiters
var speedConsumptionInLiters: [TTSpeedConsumption] = [TTSpeedConsumptionMake(10, 6.5),
                                                      TTSpeedConsumptionMake(30, 7.0),
                                                      TTSpeedConsumptionMake(50, 8.0),
                                                      TTSpeedConsumptionMake(70, 8.4),
                                                      TTSpeedConsumptionMake(90, 7.7),
                                                      TTSpeedConsumptionMake(120, 7.5),
                                                      TTSpeedConsumptionMake(150, 9.0)]
let query = TTRouteQueryBuilder.create(withDest: TTCoordinate.UTRECHT(), andOrig: TTCoordinate.AMSTERDAM())
    .withMaxAlternatives(2)
    .withVehicleWeight(1600)
    .withCurrentFuel(inLiters: 50.0)
    .withCurrentAuxiliaryPower(inLitersPerHour: 0.2)
    .withFuelEnergyDensity(inMJoulesPerLiter: 34.2)
    .withAccelerationEfficiency(0.33)
    .withDecelerationEfficiency(0.33)
    .withUphillEfficiency(0.33)
    .withDownhillEfficiency(0.33)
    .withVehicleEngineType(.combustion)
    .withSpeedConsumption(inLitersPairs: &speedConsumptionInLiters, count: UInt(speedConsumptionInLiters.count))
    .build()
routePlanner.plan(with: query)
self.style = ETAViewStyleConsumptionLiters;
TTSpeedConsumption speedConsumptionInLiters[7];
speedConsumptionInLiters[0] = TTSpeedConsumptionMake(10, 6.5);
speedConsumptionInLiters[1] = TTSpeedConsumptionMake(30, 7.0);
speedConsumptionInLiters[2] = TTSpeedConsumptionMake(50, 8.0);
speedConsumptionInLiters[3] = TTSpeedConsumptionMake(70, 8.4);
speedConsumptionInLiters[4] = TTSpeedConsumptionMake(90, 7.7);
speedConsumptionInLiters[5] = TTSpeedConsumptionMake(120, 7.5);
speedConsumptionInLiters[6] = TTSpeedConsumptionMake(150, 9.0);
TTRouteQuery *query = [[[[[[[[[[[[[TTRouteQueryBuilder
    createWithDest:[TTCoordinate UTRECHT]
           andOrig:[TTCoordinate AMSTERDAM]] withMaxAlternatives:2]
    withVehicleWeight:1600] withCurrentFuelInLiters:50.0]
    withCurrentAuxiliaryPowerInLitersPerHour:0.2]
    withFuelEnergyDensityInMJoulesPerLiter:34.2]
    withAccelerationEfficiency:0.33] withDecelerationEfficiency:0.33]
    withUphillEfficiency:0.33] withDownhillEfficiency:0.33]
    withVehicleEngineType:TTOptionVehicleEngineTypeCombustion]
    withSpeedConsumptionInLitersPairs:speedConsumptionInLiters
                                count:7] build];
[self.routePlanner planRouteWithQuery:query];

 

To request a route and calculate the consumption model for an electric vehicle:

_

style = ETAView.ETAViewStyle.consumptionKWh
var speedConsumptionInkWh: [TTSpeedConsumption] = [TTSpeedConsumptionMake(10, 5.0),
                                                   TTSpeedConsumptionMake(30, 10.0),
                                                   TTSpeedConsumptionMake(50, 15.0),
                                                   TTSpeedConsumptionMake(70, 20.0),
                                                   TTSpeedConsumptionMake(90, 25.0),
                                                   TTSpeedConsumptionMake(120, 30.0)]
let query = TTRouteQueryBuilder.create(withDest: TTCoordinate.UTRECHT(), andOrig: TTCoordinate.AMSTERDAM())
    .withMaxAlternatives(2)
    .withVehicleWeight(1600)
    .withCurrentChargeInkWh(43)
    .withMaxChargeInkWh(85)
    .withAuxiliaryPowerInkW(1.7)
    .withAccelerationEfficiency(0.33)
    .withDecelerationEfficiency(0.33)
    .withUphillEfficiency(0.33)
    .withDownhillEfficiency(0.33)
    .withVehicleEngineType(.electric)
    .withSpeedConsumptionInkWhPairs(&speedConsumptionInkWh, count: UInt(speedConsumptionInkWh.count))
    .build()
routePlanner.plan(with: query)
self.style = ETAViewStyleConsumptionKWh;
TTSpeedConsumption speedConsumptionInkWh[6];
speedConsumptionInkWh[0] = TTSpeedConsumptionMake(10, 5.0);
speedConsumptionInkWh[1] = TTSpeedConsumptionMake(30, 10.0);
speedConsumptionInkWh[2] = TTSpeedConsumptionMake(50, 15.0);
speedConsumptionInkWh[3] = TTSpeedConsumptionMake(70, 20.0);
speedConsumptionInkWh[4] = TTSpeedConsumptionMake(90, 25.0);
speedConsumptionInkWh[5] = TTSpeedConsumptionMake(120, 30.0);
TTRouteQuery *query = [[[[[[[[[[[[[TTRouteQueryBuilder
    createWithDest:[TTCoordinate UTRECHT]
           andOrig:[TTCoordinate AMSTERDAM]] withMaxAlternatives:2]
    withVehicleWeight:1600] withCurrentChargeInkWh:43] withMaxChargeInkWh:85]
    withAuxiliaryPowerInkW:1.7] withAccelerationEfficiency:0.33]
    withDecelerationEfficiency:0.33] withUphillEfficiency:0.33]
    withDownhillEfficiency:0.33]
    withVehicleEngineType:(TTOptionVehicleEngineTypeElectric)]
    withSpeedConsumptionInkWhPairs:speedConsumptionInkWh
                             count:6] build];
[self.routePlanner planRouteWithQuery:query];

 



image

Combustion

image

Electric

Supporting Points

Allow your user to reconstruct his/her route using supporting points. Supporting points
can be combined with minDeviationDistance or minDeviationTime constraints. When these constraints are used,
the alternative routes will follow the reference route from the origin point for the given time or distance.
In other words, alternative routes just diverge from the reference route after the given constraints.
When using supporting points, intermediate locations (waypoints) are not supported.

Sample use case: You have route coordinates saved on your device.
You want to reconstruct the route based on the coordinates (supporting points)
and calculate zero or more alternative routes to this reference route.

To request a route with supporting points support:

_

let query = TTRouteQueryBuilder.create(withDest: TTCoordinate.PORTUGAL_COIMBRA(), andOrig: TTCoordinate.PORTUGAL_NOVA())
    .withMaxAlternatives(1)
    .withMinDeviationTime(0)
    .withSupportingPoints(&supprotingPoints, count: UInt(supprotingPoints.count))
    .withMinDeviationDistance(10000)
    .build()
routePlanner.plan(with: query)
TTRouteQuery *query =
    [[[[[[TTRouteQueryBuilder createWithDest:[TTCoordinate PORTUGAL_COIMBRA]
                                     andOrig:[TTCoordinate PORTUGAL_NOVA]]
        withMaxAlternatives:1] withMinDeviationTime:0]
        withSupportingPoints:self.suporrtingPoints
                       count:5] withMinDeviationDistance:0] build];
[self.routePlanner planRouteWithQuery:query];

 



image

Min. deviation distance: 0 m

image

Min. deviation distance: 10 km

Reachable range

The Reachable Range component calculates a set of locations that can be reached from the origin point. It optimizes for routes with a given route-type (e.g. fastest, eco, etc) but limits the range for the given budget and consumption parameters.
It uses Calculate Reachable Range API so you can find all details in the service documentation.

Sample use case: You are preparing to a trip and you would like to check how far you can drive on your battery or tank, or within specific time limit so you plan your journey.

The example below shows a number of points that are reachable based on one of specified model for:
* Combustion engine
* Electric engine
* Time-2h limit on an electric car (time budget model is available for both electric and combustion engines)

Use the code sample below for implementing a similar use case.

To request a reachable range create a ReachableRangeQuery:

_

let query = TTReachableRangeQueryBuilder.create(withCenterLocation: TTCoordinate.AMSTERDAM())
    .withSpeedConsumption(inLitersPairs: &speedConsumption, count: UInt(speedConsumption.count))
    .withVehicleWeight(1600)
    .withCurrentFuel(inLiters: 43)
    .withFuelEnergyDensity(inMJoulesPerLiter: 34.2)
    .withCurrentAuxiliaryPower(inLitersPerHour: 1.7)
    .withAccelerationEfficiency(0.33)
    .withDecelerationEfficiency(0.33)
    .withUphillEfficiency(0.33)
    .withDownhillEfficiency(0.33)
    .withVehicleEngineType(.combustion)
    .withFuelBudget(inLiters: 5)
    .build()
TTSpeedConsumption consumption[1];
consumption[0] = TTSpeedConsumptionMake(50, 6.3);
TTReachableRangeQuery *query = [[[[[[[[[[[[[TTReachableRangeQueryBuilder
    createWithCenterLocation:[TTCoordinate AMSTERDAM]]
    withSpeedConsumptionInLitersPairs:consumption
                                count:1] withVehicleWeight:1600]
    withCurrentFuelInLiters:43] withFuelEnergyDensityInMJoulesPerLiter:34.2]
    withCurrentAuxiliaryPowerInLitersPerHour:1.7]
    withAccelerationEfficiency:0.33] withDecelerationEfficiency:0.33]
    withUphillEfficiency:0.33] withDownhillEfficiency:0.33]
    withVehicleEngineType:TTOptionVehicleEngineTypeCombustion]
    withFuelBudgetInLiters:5] build];

 

The result can be observed with TTReachableRangeDelegate:

_

func reachableRange(_: TTReachableRange, completedWithResult response: TTReachableRangeResponse) {
}
- (void)reachableRange:(TTReachableRange *)range
    completedWithResult:(TTReachableRangeResponse *)response {
}

 

_

func reachableRange(_: TTReachableRange, completedWith responseError: TTResponseError) {
}
- (void)reachableRange:(TTReachableRange *)range
    completedWithResponseError:(TTResponseError *)responseError {
}

 



image

Fuel budget: 5 liters

image

Energy budget: 5 kWh

image

Time budget: 2h

You can use the output of the returned set of locations for other interacting use cases e.g. searching for places on the route to one (many) reachable point(s) with Search along the route or within the polygon boundaries with Geometry search features of Maps SDK.

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, at first you have to create a compound query:

_

let batchQuery = TTBatchRouteQueryBuilder.createReachableRangeQuery(queryFactory.createReachableRangeQueryForElectric())
    .add(queryFactory.createReachableRangeQueryForCombustion())
    .add(queryFactory.createReachableRangeQueryForElectricLimitTo2Hours())
    .build()
batchRoute.batchRoute(with: batchQuery)
TTBatchRouteQuery *batchQuery = [[[[TTBatchRouteQueryBuilder
    createReachableRangeQuery:[self.queryFactory
                                      createReachableRangeQueryForElectric]]
    addReachableRangeQuery:[self.queryFactory
                                   createReachableRangeQueryForCombustion]]
    addReachableRangeQuery:
        [self.queryFactory createReachableRangeQueryForElectricLimitTo2Hours]]
    build];
[self.batchRoute batchRouteWithQuery:batchQuery];

 

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 on the polylines.



image

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

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 Online Batch Routing API
so you can find all details about it in the service documentation.

Sample use case: You are preparing to 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 Online Batch Routing API
or JavaDocs of this SDK under 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 on 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 code sample below for implementing a similar use case.

To request a batch query create a TTBatchRouteQuery:

_

let batchQuery = TTBatchRouteQueryBuilder.createRouteQuery(queryCar)
    .add(queryTruck)
    .add(queryPedestrain)
    .build()
TTBatchRouteQuery *batchQuery =
    [[[[TTBatchRouteQueryBuilder createRouteQuery:queryCar]
        addRouteQuery:queryTruck] addRouteQuery:queryPedestrain] build];

 

and pass it to the routing API:

_

batchRoute = TTBatchRoute()
batchRoute.delegate = self
batchRoute.batchRoute(with: batchQuery)
self.batchRoute = [[TTBatchRoute alloc] init];
self.batchRoute.delegate = self;
[self.batchRoute batchRouteWithQuery:batchQuery];

 

Setup of the common params for batch routing query:

_

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

 

The result can be observed with TTBatchRouteResponseDelegate:

_

func batch(_: TTBatchRoute, completedWith response: TTBatchRouteResponse) {
    response.visit(self)
}
func batch(_: TTBatchRoute, failedWithError responseError: TTResponseError) {
}
func visitRoute(_ response: TTRouteResult) {
    let mapRoute = TTMapRoute(coordinatesData: response.routes.first!,
                              with: TTMapRouteStyle.defaultInactive(),
                              imageStart: TTMapRoute.defaultImageDeparture(),
                              imageEnd: TTMapRoute.defaultImageDestination())
    mapRoute.extraData = response.routes.first?.summary
    mapView.routeManager.add(mapRoute)
    progress.hide()
    displayRouteOverview()
}
- (void)batch:(TTBatchRoute *_Nonnull)route
    completedWithResponse:(TTBatchRouteResponse *_Nonnull)response {
  [response visit:self];
}
- (void)batch:(TTBatchRoute *_Nonnull)route
    failedWithError:(TTResponseError *_Nonnull)responseError {
}
- (void)visitRoute:(TTRouteResult *)response {
  TTMapRoute *mapRoute =
      [TTMapRoute routeWithCoordinatesData:response.routes.firstObject
                            withRouteStyle:TTMapRouteStyle.defaultInactiveStyle
                                imageStart:TTMapRoute.defaultImageDeparture
                                  imageEnd:TTMapRoute.defaultImageDestination];
  mapRoute.extraData = response.routes.firstObject.summary;
  [self.mapView.routeManager addRoute:mapRoute];
  [self.progress hide];
  [self.mapView.routeManager showAllRoutesOverview];
}

 



image

Travel modes: car, truck, pedestrian

image

Route type: fastest, shortest, eco

image

Avoids: motorways, ferries, toll roads

You can select route and get information about ETA and distances.

Matrix routing

Allow your users to send multiple synchronous routing requests with Matrix Routing components. You can calculate a matrix of route summaries for a set of routes defined with origin and destination locations to compare them in an easy way.

Matrix Routing sdk components use Online Matrix Routing API so you can find all details about it in the service documentation.

The set of origins and the set of destinations can be thought of as the column and row headers of a table and each cell in the table contains the costs of routing from the origin to the destination for that cell.
There are generally three types of use cases for Matrix Routing:

  • 1-to-many = from one origin (e.g. your current location) to many destinations (e.g. POIs)

  • many-to-many = from many origins (e.g. taxis) to many destinations (e.g. passengers)

  • many-to-1 = from many origins (e.g. ambulances) to one destination (e.g. patient)

Try out the use cases below in your app.

Sample use case: (One to many) I know a few restaurants and I would like to know to which one I can get to the fastest

1 origin – Amsterdam, 5 restaurants in Amsterdam. The shortest ETA is the active route.


image

One to Many

Sample use case: (Many to many) There are a few taxis and a few passengers to pick up, you would like to compare ETAs for each pairs passengers-taxis to choose the most optimal combination.

2 origins (taxies) and 2 (destinations) passengers. Render all routes for all taxies. The active routes are the ones with the shortest ETA for each pair.


image

Many to Many

Use the code sample below for implementing a similar use case.

To request a matrix query create a MatrixRoutingQuery:

_

let query = TTMatrixRouteQueryBuilder.create(withOrigin: TTCoordinate.PASSENGER_ONE(),
                                             withDestination: TTCoordinate.TAXI_ONE())
    .addOrigin(TTCoordinate.PASSENGER_TWO())
    .addDestination(TTCoordinate.TAXI_TWO())
    .build()
TTMatrixRouteQuery *query = [[[[[[TTMatrixRouteQueryBuilder
    createWithOrigin:TTCoordinate.AMSTERDAM_CENTER_LOCATION
     withDestination:TTCoordinate.AMSTERDAM_RESTAURANT_BRIDGES]
    addDestination:TTCoordinate.AMSTERDAM_RESTAURANT_GREETJE]
    addDestination:TTCoordinate.AMSTERDAM_RESTAURANT_LA_RIVE]
    addDestination:TTCoordinate.AMSTERDAM_RESTAURANT_WAGAMAMA]
    addDestination:TTCoordinate.AMSTERDAM_RESTAURANT_ENVY] build];

and pass it to the routing API:

_

matrixRouting.matrixRoute(with: query)
[self.matrix matrixRouteWithQuery:query];

The result can be acquire by delegate or by completion block

_

func matrix(_: TTMatrixRoute, completedWith response: TTMatrixRouteResponse) {
}
func matrix(_: TTMatrixRoute, completedWith responseError: TTResponseError) {
}
- (void)matrix:(TTMatrixRoute *)matrix
    completedWithResponse:(TTMatrixRouteResponse *)response {
}
- (void)matrix:(TTMatrixRoute *)matrix
    completedWithResponseError:(TTResponseError *)responseError {
}

You can obtain detailed summary of every route in matrix (eg. ETA, delay, distances).

You are here