A routing matrix is a rectangular array arranged in rows and columns, where rows correspond to origins and columns to destinations. Entries in the matrix are integers that describe either the travel times in seconds or distances in meters, depending on what was requested.
The first dimension of a matrix is always the number of rows N. The second dimension is the number of columns M. Such a matrix is called an M x N matrix and has this general form:
|origins\destinations||0||1||...||M - 1|
|0||value 0 → 0||value 0 → 1||...||value 0 → M - 1|
|1||value 1 → 0||value 1 → 1||...||value 1 → M - 1|
|N - 1||value N - 1 → 0||value N - 1 → 1||...||value N - 1 → M - 1|
If the numbers of origins and destinations are equal, then the corresponding matrix is square. By definition, for each entry on the diagonal the origin and destination coincide. However, the matrix is not symmetrical, meaning the entry for origin o to destination d is not the same as the entry for origin d to origin o, since a return route of a shortest route in most cases is a different one.
The API response represents a routing matrix as a one-dimensional array. Each entry at position k corresponds to an entry in the matrix at row i and column j by the formula:
k = M · i + j.
That is, the first M entries are the first row, the next M entries are the second row, and so on.
Sometimes it's impossible to calculate a route between an origin and a destination. This might happen because the destination is not reachable from the origin, or because either the origin or destination could not be matched to the map. In this case, if at least one such error happens, the service adds another matrix of integers to the response, with each entry in the matrix containing an error code. The code
0 means no error. The code
3 means that the route was calculated, but has some violations, for example, it uses a ferry when ferry avoidance was requested, or goes through a road that is blocked at the desired driving time.
For other possible values, see the API Reference.