calculateRouteMatrix method

Future<CalculateRouteMatrixResponse> calculateRouteMatrix({
  1. required String calculatorName,
  2. required List<List<double>> departurePositions,
  3. required List<List<double>> destinationPositions,
  4. CalculateRouteCarModeOptions? carModeOptions,
  5. bool? departNow,
  6. DateTime? departureTime,
  7. DistanceUnit? distanceUnit,
  8. String? key,
  9. TravelMode? travelMode,
  10. CalculateRouteTruckModeOptions? truckModeOptions,
})
Calculates a route matrix given the following required parameters: 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 DepartureTime or DepartNow. 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 CarModeOptions if traveling by Car, or TruckModeOptions if traveling by Truck.

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 Car use the CarModeOptions parameter.
  • If traveling by Truck use the TruckModeOptions parameter.

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);
}