calculateRoutes method
- required List<
double> destination, - required List<
double> origin, - RouteAllowOptions? allow,
- String? arrivalTime,
- RouteAvoidanceOptions? avoid,
- bool? departNow,
- String? departureTime,
- RouteDestinationOptions? destinationOptions,
- RouteDriverOptions? driver,
- RouteExclusionOptions? exclude,
- MeasurementSystem? instructionsMeasurementSystem,
- String? key,
- List<
String> ? languages, - List<
RouteLegAdditionalFeature> ? legAdditionalFeatures, - GeometryFormat? legGeometryFormat,
- int? maxAlternatives,
- RoutingObjective? optimizeRoutingFor,
- RouteOriginOptions? originOptions,
- List<
RouteSpanAdditionalFeature> ? spanAdditionalFeatures, - RouteTollOptions? tolls,
- RouteTrafficOptions? traffic,
- RouteTravelMode? travelMode,
- RouteTravelModeOptions? travelModeOptions,
- RouteTravelStepType? travelStepType,
- List<
RouteWaypoint> ? waypoints,
CalculateRoutes computes routes given the following required
parameters: Origin and Destination.
For more information, see Calculate routes in the Amazon Location Service Developer Guide.
May throw AccessDeniedException.
May throw InternalServerException.
May throw ThrottlingException.
May throw ValidationException.
Parameter destination :
The final position for the route. In the World Geodetic System (WGS 84)
format: [longitude, latitude].
Parameter origin :
The start position for the route in World Geodetic System (WGS 84) format:
[longitude, latitude].
Parameter allow :
Features that are allowed while calculating a route. Not supported in
ap-southeast-1 and ap-southeast-5 regions for GrabMaps
customers.
Parameter arrivalTime :
Time of arrival at the destination. Not supported in
ap-southeast-1 and ap-southeast-5 regions for GrabMaps
customers.
Time format:YYYY-MM-DDThh:mm:ss.sssZ |
YYYY-MM-DDThh:mm:ss.sss+hh:mm
Examples:
2020-04-22T17:57:24Z
2020-04-22T17:57:24+02:00
Parameter avoid :
Features that are avoided while calculating a route. Avoidance is on a
best-case basis. If an avoidance can't be satisfied for a particular case,
it violates the avoidance and the returned response produces a notice for
the violation. For GrabMaps
customers, ap-southeast-1 and ap-southeast-5
regions support only ControlledAccessHighways,
Ferries, and TollRoads
Parameter departNow :
Uses the current time as the time of departure.
Parameter departureTime :
Time of departure from the origin.
Time format:YYYY-MM-DDThh:mm:ss.sssZ |
YYYY-MM-DDThh:mm:ss.sss+hh:mm
Examples:
2020-04-22T17:57:24Z
2020-04-22T17:57:24+02:00
Parameter destinationOptions :
Destination related options. Not supported in ap-southeast-1
and ap-southeast-5 regions for GrabMaps
customers.
Parameter driver :
Driver related options. Not supported in ap-southeast-1 and
ap-southeast-5 regions for GrabMaps
customers.
Parameter exclude :
Features to be strictly excluded while calculating the route. Not
supported in ap-southeast-1 and ap-southeast-5
regions for GrabMaps
customers.
Parameter instructionsMeasurementSystem :
Measurement system to be used for instructions within steps in the
response.
Parameter key :
Optional: The API key to be used for authorization. Either an API key or
valid SigV4 signature must be provided when making a request.
Parameter languages :
List of languages for instructions within steps in the response. Not
supported in ap-southeast-1 and ap-southeast-5
regions for GrabMaps
customers.
Parameter legAdditionalFeatures :
A list of optional additional parameters such as timezone that can be
requested for each result. For GrabMaps
customers, ap-southeast-1 and ap-southeast-5
regions support only PassThroughWaypoints,
Summary, and TravelStepInstructions
-
Elevation: Retrieves the elevation information for each location. -
Incidents: Provides information on traffic incidents along the route. -
PassThroughWaypoints: Indicates waypoints that are passed through without stopping. -
Summary: Returns a summary of the route, including distance and duration. -
Tolls: Supplies toll cost information along the route. -
TravelStepInstructions: Provides step-by-step instructions for travel along the route. -
TruckRoadTypes: Returns information about road types suitable for trucks. -
TypicalDuration: Gives typical travel duration based on historical data. -
Zones: Specifies the time zone information for each waypoint.
Parameter legGeometryFormat :
Specifies the format of the geometry returned for each leg of the route.
You can choose between two different geometry encoding formats.
FlexiblePolyline: A compact and precise encoding format for
the leg geometry. For more information on the format, see the GitHub
repository for https://github.com/aws-geospatial/polyline.
Simple: A less compact encoding, which is easier to decode
but may be less precise and result in larger payloads.
Parameter maxAlternatives :
Maximum number of alternative routes to be provided in the response, if
available. For GrabMaps
customers, ap-southeast-1 and ap-southeast-5
regions support only up to 3 alternative routes.
Parameter optimizeRoutingFor :
Controls the trade-off between achieving the shortest travel time
(FastestRoute) and achieving the shortest physical distance
((ShortestRoute) when calculating each route in the matrix.
Default value: FastestRoute
Parameter originOptions :
Specifies how the origin point should be matched to the road network and
any routing constraints that apply when the traveler is departing the
origin. Not supported in ap-southeast-1 and
ap-southeast-5 regions for GrabMaps
customers.
Parameter spanAdditionalFeatures :
A list of optional features such as SpeedLimit that can be
requested for a Span. A span is a section of a Leg for which the requested
features have the same values. Not supported in
ap-southeast-1 and ap-southeast-5 regions for GrabMaps
customers.
Parameter tolls :
Toll related options. Not supported in ap-southeast-1 and
ap-southeast-5 regions for GrabMaps
customers.
Parameter traffic :
Traffic related options. Not supported in ap-southeast-1 and
ap-southeast-5 regions for GrabMaps
customers.
Parameter travelMode :
Specifies the mode of transport when calculating a route. Used in
estimating the speed of travel and road compatibility. For GrabMaps
customers, ap-southeast-1 and ap-southeast-5
regions support only Car, Pedestrian, and
Scooter values.
Default value: Car
Parameter travelModeOptions :
Travel mode related options for the provided travel mode. For GrabMaps
customers, ap-southeast-1 and ap-southeast-5
regions support only Car and Pedestrian travel
mode options.
Parameter travelStepType :
Type of step returned by the response. Default provides basic
steps intended for web based applications. TurnByTurn
provides detailed instructions with more granularity intended for a turn
based navigation system. For GrabMaps
customers, ap-southeast-1 and ap-southeast-5
regions Default does not return any steps.
Parameter waypoints :
List of waypoints between the Origin and Destination. For GrabMaps
customers, ap-southeast-1 and ap-southeast-5
regions max length is 100.
Max length: 23
Implementation
Future<CalculateRoutesResponse> calculateRoutes({
required List<double> destination,
required List<double> origin,
RouteAllowOptions? allow,
String? arrivalTime,
RouteAvoidanceOptions? avoid,
bool? departNow,
String? departureTime,
RouteDestinationOptions? destinationOptions,
RouteDriverOptions? driver,
RouteExclusionOptions? exclude,
MeasurementSystem? instructionsMeasurementSystem,
String? key,
List<String>? languages,
List<RouteLegAdditionalFeature>? legAdditionalFeatures,
GeometryFormat? legGeometryFormat,
int? maxAlternatives,
RoutingObjective? optimizeRoutingFor,
RouteOriginOptions? originOptions,
List<RouteSpanAdditionalFeature>? spanAdditionalFeatures,
RouteTollOptions? tolls,
RouteTrafficOptions? traffic,
RouteTravelMode? travelMode,
RouteTravelModeOptions? travelModeOptions,
RouteTravelStepType? travelStepType,
List<RouteWaypoint>? waypoints,
}) async {
final $query = <String, List<String>>{
if (key != null) 'key': [key],
};
final $payload = <String, dynamic>{
'Destination': destination.map(_s.encodeJsonDouble).toList(),
'Origin': origin.map(_s.encodeJsonDouble).toList(),
if (allow != null) 'Allow': allow,
if (arrivalTime != null) 'ArrivalTime': arrivalTime,
if (avoid != null) 'Avoid': avoid,
if (departNow != null) 'DepartNow': departNow,
if (departureTime != null) 'DepartureTime': departureTime,
if (destinationOptions != null) 'DestinationOptions': destinationOptions,
if (driver != null) 'Driver': driver,
if (exclude != null) 'Exclude': exclude,
if (instructionsMeasurementSystem != null)
'InstructionsMeasurementSystem': instructionsMeasurementSystem.value,
if (languages != null) 'Languages': languages,
if (legAdditionalFeatures != null)
'LegAdditionalFeatures':
legAdditionalFeatures.map((e) => e.value).toList(),
if (legGeometryFormat != null)
'LegGeometryFormat': legGeometryFormat.value,
if (maxAlternatives != null) 'MaxAlternatives': maxAlternatives,
if (optimizeRoutingFor != null)
'OptimizeRoutingFor': optimizeRoutingFor.value,
if (originOptions != null) 'OriginOptions': originOptions,
if (spanAdditionalFeatures != null)
'SpanAdditionalFeatures':
spanAdditionalFeatures.map((e) => e.value).toList(),
if (tolls != null) 'Tolls': tolls,
if (traffic != null) 'Traffic': traffic,
if (travelMode != null) 'TravelMode': travelMode.value,
if (travelModeOptions != null) 'TravelModeOptions': travelModeOptions,
if (travelStepType != null) 'TravelStepType': travelStepType.value,
if (waypoints != null) 'Waypoints': waypoints,
};
final response = await _protocol.sendRaw(
payload: $payload,
method: 'POST',
requestUri: '/v2/routes',
queryParams: $query,
exceptionFnMap: _exceptionFns,
);
final $json = await _s.jsonFromResponse(response);
return CalculateRoutesResponse(
legGeometryFormat: GeometryFormat.fromString(
($json['LegGeometryFormat'] as String?) ?? ''),
notices: (($json['Notices'] as List?) ?? const [])
.nonNulls
.map((e) => RouteResponseNotice.fromJson(e as Map<String, dynamic>))
.toList(),
routes: (($json['Routes'] as List?) ?? const [])
.nonNulls
.map((e) => Route.fromJson(e as Map<String, dynamic>))
.toList(),
pricingBucket: _s.extractHeaderStringValue(
response.headers, 'x-amz-geo-pricing-bucket')!,
);
}