Matrix Service
The time distance matrix service takes a sources and targets to list locations. This allows you to set the source (origin) locations separately from the target (destination) locations. The set of origins may be disjoint (not overlapping) with the set of destinations. In other words, the target locations do not have to include any locations from source locations. The time-distance matrix can return a row matrix, a column matrix, or a general matrix of computed time and distance, depending on your input for the sources and targets parameters. The general case is a row ordered matrix with the time and distance from each source location to each target location. A row vector is considered a one_to_many time-distance matrix where there is one source location and multiple target locations. The time and distance from the source location to all target locations is returned. A column matrix represents a many_to_one time-distance matrix where there are many sources and one target. Another special case is when the source location list is the same as the target location list. Here, a diagonal (square matrix with [0,0.00] on the diagonal elements) matrix is returned. The is special case is often used as the input to optimized routing problems.
Required Parameters
- Query Param:
token
→ Required /matrix/?token=YOUR_TOKEN (Authorization, otherwise401 Token required
error will occur)
- Body JSON:
sources
→ Required (List of source coordinates)targets
→ Optional (List of target coordinates, defaults to sources if omitted)costing
→ Required (Travel mode, e.g.pedestrian
,auto
,bicycle
)
Examples (Copy & Paste)
One-to-Many
{ "sources": [ { "lat": 40.744014, "lon": -73.990508 } ], "targets": [ { "lat": 40.744014, "lon": -73.990508 }, { "lat": 40.739735, "lon": -73.979713 }, { "lat": 40.752522, "lon": -73.985015 }, { "lat": 40.750117, "lon": -73.983704 }, { "lat": 40.750552, "lon": -73.993519 } ], "costing": "pedestrian" }
Many-to-One
{ "sources": [ { "lat": 40.744014, "lon": -73.990508 }, { "lat": 40.739735, "lon": -73.979713 }, { "lat": 40.752522, "lon": -73.985015 }, { "lat": 40.750117, "lon": -73.983704 }, { "lat": 40.750552, "lon": -73.993519 } ], "targets": [ { "lat": 40.750552, "lon": -73.993519 } ], "costing": "pedestrian" }
Many-to-Many
{ "sources": [ { "lat": 40.744014, "lon": -73.990508 }, { "lat": 40.739735, "lon": -73.979713 }, { "lat": 40.752522, "lon": -73.985015 }, { "lat": 40.750117, "lon": -73.983704 }, { "lat": 40.750552, "lon": -73.993519 } ], "targets": [ { "lat": 40.744014, "lon": -73.990508 }, { "lat": 40.739735, "lon": -73.979713 }, { "lat": 40.752522, "lon": -73.985015 }, { "lat": 40.750117, "lon": -73.983704 }, { "lat": 40.750552, "lon": -73.993519 } ], "costing": "pedestrian" }
Costing parameter
The Time-Distance Matrix service uses the auto, bicycle, pedestrian and bikeshare and other costing models available in the route service. Exception: multimodal costing is not supported for the time-distance matrix service at this time.
Other Request Option
Option | Description |
---|---|
verbose | If true , it will output a flat list of objects for distances & durations explicitly specifying the source & target indices. If false , will return more compact, nested row-major distances & durations arrays and not echo sources and targets . Default: true . |
shape_format | Specifies the optional format for the path shape of each connection. One of polyline6 , polyline5 , geojson , or no_shape (default). |
Outputs of the matrix service
Depending on the verbose
(default: true
) request parameter, the result of the Time-Distance Matrix service is different. In both ("verbose": true
and "verbose": false
) cases, these parameters are present:
Item | Description |
---|---|
algorithm | The algorithm used to compute the results. Can be "timedistancematrix" , "costmatrix" , or "timedistancebssmatrix" . |
units | Distance units for output. Allowable unit types are "miles" and "kilometers" . If no unit type is specified in the input, the units default to "kilometers" . |
warnings (optional) | This array may contain warning objects informing about deprecated request parameters, clamped values etc. |
Verbose mode ("verbose": true)
The following parameters are only present in "verbose": true mode:
Item | Description |
---|---|
sources | The sources passed to the request. |
targets | The targets passed to the request. |
sources_to_targets | An array of time and distance between the sources and the targets. The array is row-ordered, meaning the time and distance from the first location to all others forms the first row of the array, followed by the time and distance from the second source location to all target locations, etc. The Object contained in the arrays contains the following fields:
max_time_dep_distance_matrix this is skipped. |
Concise mode ("verbose": false)
Item | Description |
---|---|
sources_to_target | Returns an object with durations and distances as row-ordered contents of the values above. |