THIS SDK ISDEPRECATED.

We rolled out a new and better SDK for you.

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 the 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 following use cases in your app.

Sample use case: (One to many) I know a few restaurants and I would like to know 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 following code sample to implement a similar use case.

To request a matrix query create a MatrixRoutingQuery:

1let query = TTMatrixRouteQueryBuilder.create(withOrigin: TTCoordinate.PASSENGER_ONE(),
2 withDestination: TTCoordinate.TAXI_ONE())
3 .addOrigin(TTCoordinate.PASSENGER_TWO())
4 .addDestination(TTCoordinate.TAXI_TWO())
5 .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 acquired by delegate or by completion block:

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

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