calculateRouteMatrix method
- required String calculatorName,
- required List<
List< departurePositions,double> > - required List<
List< destinationPositions,double> > - CalculateRouteCarModeOptions? carModeOptions,
- bool? departNow,
- DateTime? departureTime,
- DistanceUnit? distanceUnit,
- String? key,
- TravelMode? travelMode,
- CalculateRouteTruckModeOptions? truckModeOptions,
DeparturePositions and DestinationPositions.
CalculateRouteMatrix calculates routes and returns the travel
time and travel distance from each departure position to each destination
position in the request. For example, given departure positions A and B,
and destination positions X and Y, CalculateRouteMatrix will
return time and distance for routes from A to X, A to Y, B to X, and B to
Y (in that order). The number of results returned (and routes calculated)
will be the number of DeparturePositions times the number of
DestinationPositions.
Requires that you first create
a route calculator resource.
By default, a request that doesn't specify a departure time uses the best time of day to travel with the best traffic conditions when calculating routes.
Additional options include:
-
Specifying a departure time using either
DepartureTimeorDepartNow. This calculates routes based on predictive traffic data at the given time. -
Specifying
a travel mode using TravelMode sets the transportation mode used to
calculate the routes. This also lets you specify additional route
preferences in
CarModeOptionsif traveling byCar, orTruckModeOptionsif traveling byTruck.
May throw AccessDeniedException.
May throw InternalServerException.
May throw ResourceNotFoundException.
May throw ThrottlingException.
May throw ValidationException.
Parameter calculatorName :
The name of the route calculator resource that you want to use to
calculate the route matrix.
Parameter departurePositions :
The list of departure (origin) positions for the route matrix. An array of
points, each of which is itself a 2-value array defined in WGS 84
format: [longitude, latitude]. For example,
[-123.115, 49.285].
Valid Values: [-180 to 180,-90 to 90]
Parameter destinationPositions :
The list of destination positions for the route matrix. An array of
points, each of which is itself a 2-value array defined in WGS 84
format: [longitude, latitude]. For example,
[-122.339, 47.615]
Valid Values: [-180 to 180,-90 to 90]
Parameter carModeOptions :
Specifies route preferences when traveling by Car, such as
avoiding routes that use ferries or tolls.
Requirements: TravelMode must be specified as
Car.
Parameter departNow :
Sets the time of departure as the current time. Uses the current time to
calculate the route matrix. You can't set both DepartureTime
and DepartNow. If neither is set, the best time of day to
travel with the best traffic conditions is used to calculate the route
matrix.
Default Value: false
Valid Values: false | true
Parameter departureTime :
Specifies the desired time of departure. Uses the given time to calculate
the route matrix. You can't set both DepartureTime and
DepartNow. If neither is set, the best time of day to travel
with the best traffic conditions is used to calculate the route matrix.
-
In ISO
8601 format:
YYYY-MM-DDThh:mm:ss.sssZ. For example,2020–07-2T12:15:20.000Z+01:00
Parameter distanceUnit :
Set the unit system to specify the distance.
Default Value: Kilometers
Parameter key :
The optional API
key to authorize the request.
Parameter travelMode :
Specifies the mode of transport when calculating a route. Used in
estimating the speed of travel and road compatibility.
The TravelMode you specify also determines how you specify
route preferences:
-
If traveling by
Caruse theCarModeOptionsparameter. -
If traveling by
Truckuse theTruckModeOptionsparameter.
Implementation
Future<CalculateRouteMatrixResponse> calculateRouteMatrix({
required String calculatorName,
required List<List<double>> departurePositions,
required List<List<double>> destinationPositions,
CalculateRouteCarModeOptions? carModeOptions,
bool? departNow,
DateTime? departureTime,
DistanceUnit? distanceUnit,
String? key,
TravelMode? travelMode,
CalculateRouteTruckModeOptions? truckModeOptions,
}) async {
final $query = <String, List<String>>{
if (key != null) 'key': [key],
};
final $payload = <String, dynamic>{
'DeparturePositions': departurePositions,
'DestinationPositions': destinationPositions,
if (carModeOptions != null) 'CarModeOptions': carModeOptions,
if (departNow != null) 'DepartNow': departNow,
if (departureTime != null) 'DepartureTime': iso8601ToJson(departureTime),
if (distanceUnit != null) 'DistanceUnit': distanceUnit.value,
if (travelMode != null) 'TravelMode': travelMode.value,
if (truckModeOptions != null) 'TruckModeOptions': truckModeOptions,
};
final response = await _protocol.send(
payload: $payload,
method: 'POST',
requestUri:
'/routes/v0/calculators/${Uri.encodeComponent(calculatorName)}/calculate/route-matrix',
queryParams: $query,
exceptionFnMap: _exceptionFns,
);
return CalculateRouteMatrixResponse.fromJson(response);
}