Flexible Mode
Flexible mode provides capabilities such as Custom options, Time Awareness (including Live Traffic), Unlimited Region but it has a limited Matrix Size. Given a list of origins and a list of destinations, the service computes the shortest travel times or distances between every pair of origin and destination. These results make up the entries of the routing matrix.
In order to provide support for custom routing options, time awareness, and routes of arbitrary length, Flexible Mode cannot benefit from the optimizations that give Region and Profile modes their high performance. Due to this performance limitation, Flexible Mode requests are limited to:
at most 15 origins and 100 destinations (15 x 100)
at most 100 origins and 1 destination (100 x 1)
Formulating a request
The flexible mode is utilized when:
the region definition = WorldRegion and no profile parameter is specified The service applies live and historical traffic information unless explicitly disabled by setting departureTime to the special value any.
Below is an example of a 3x3 matrix request with the following origins and destinations:
San Francisco at (37.76, -122.42)
New York at (40.63, -74.09)
Austin at (30.26, -97.74)
Example
import os
from here_location_services import LS
from here_location_services.config.matrix_routing_config import (
WorldRegion,
MATRIX_ATTRIBUTES,
)
LS_API_KEY = os.environ.get("LS_API_KEY") # Get API KEY from environment.
ls = LS(api_key=LS_API_KEY)
origins = [
{"lat": 37.76, "lng": -122.42},
{"lat": 40.63, "lng": -74.09},
{"lat": 30.26, "lng": -97.74},
]
region_definition = WorldRegion()
matrix_attributes = [MATRIX_ATTRIBUTES.distances, MATRIX_ATTRIBUTES.travelTimes]
result = ls.matrix(
origins=origins,
region_definition=region_definition,
matrix_attributes=matrix_attributes,
)
result.matrix
{'numOrigins': 3,
'numDestinations': 3,
'travelTimes': [0, 154467, 92781, 154876, 0, 93882, 94302, 93955, 0],
'distances': [0, 4701596, 2831834, 4701970, 0, 2829527, 2834742, 2803612, 0]}
Attributes
Attribute |
Type |
Doc |
---|---|---|
origins |
list |
A list of dictionaries containing lat and long for origin points. |
region_definition |
object |
|
async_req |
bool |
If set to True reuqests will be sent to asynchronous matrix routing API else It will be sent to synchronous matrix routing API. For larger matrices, or longer routes, or routes in denser road networks, it is recommended to set to True. |
destinations |
list |
A list of dictionaries containing lat and long for destination points. When no destinations are specified the matrix is assumed to be quadratic with origins used as destinations. |
profile |
string |
Use values from config: |
departure_time |
|
When it is not specified, it is implicitly assumed to be the current time. The special value |
routing_mode |
string |
Use values from config: |
transport_mode |
string |
Use values from config: |
avoid_features |
list |
Use values from config: |
avoid_areas |
list |
Use object of |
truck |
object of |
Used to define truck options when transport mode is truck |
matrix_attributes |
list |
Use values from config: |