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

Matrix routing

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