optimizeWaypoints method
- required List<
double> origin, - WaypointOptimizationAvoidanceOptions? avoid,
- WaypointOptimizationClusteringOptions? clustering,
- String? departureTime,
- List<
double> ? destination, - WaypointOptimizationDestinationOptions? destinationOptions,
- WaypointOptimizationDriverOptions? driver,
- WaypointOptimizationExclusionOptions? exclude,
- String? key,
- WaypointOptimizationSequencingObjective? optimizeSequencingFor,
- WaypointOptimizationOriginOptions? originOptions,
- WaypointOptimizationTrafficOptions? traffic,
- WaypointOptimizationTravelMode? travelMode,
- WaypointOptimizationTravelModeOptions? travelModeOptions,
- List<
WaypointOptimizationWaypoint> ? waypoints,
OptimizeWaypoints calculates the optimal order to travel
between a set of waypoints to minimize either the travel time or the
distance travelled during the journey, based on road network restrictions
and the traffic pattern data.
For more information, see Optimize waypoints in the Amazon Location Service Developer Guide.
May throw AccessDeniedException.
May throw InternalServerException.
May throw ThrottlingException.
May throw ValidationException.
Parameter origin :
The start position for the route in World Geodetic System (WGS 84) format:
[longitude, latitude].
Parameter avoid :
Features that are avoided. Avoidance is on a best-case basis. If an
avoidance can't be satisfied for a particular case, this setting is
ignored.
Parameter clustering :
Clustering allows you to specify how nearby waypoints can be clustered to
improve the optimized sequence.
Parameter departureTime :
Departure time from the waypoint.
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 destination :
The final position for the route in the World Geodetic System (WGS 84)
format: [longitude, latitude].
Parameter destinationOptions :
Destination related options.
Parameter driver :
Driver related options.
Parameter exclude :
Features to be strictly excluded while calculating the route.
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 optimizeSequencingFor :
Specifies the optimization criteria for the calculated sequence.
Default value: FastestRoute.
Parameter originOptions :
Origin related options.
Parameter traffic :
Traffic-related options.
Parameter travelMode :
Specifies the mode of transport when calculating a route. Used in
estimating the speed of travel and road compatibility.
Default value: Car
Parameter travelModeOptions :
Travel mode related options for the provided travel mode.
Parameter waypoints :
List of waypoints between the Origin and
Destination, in World Geodetic System (WGS 84) format:
[longitude, latitude].
The maximum number of waypoints allowed per request:
- Maximum 50 waypoints per request
-
Maximum 20 waypoints when using constraints (
AccessHours,AppointmentTime,ServiceDuration,Heading,SideOfStreet,Before)
Implementation
Future<OptimizeWaypointsResponse> optimizeWaypoints({
required List<double> origin,
WaypointOptimizationAvoidanceOptions? avoid,
WaypointOptimizationClusteringOptions? clustering,
String? departureTime,
List<double>? destination,
WaypointOptimizationDestinationOptions? destinationOptions,
WaypointOptimizationDriverOptions? driver,
WaypointOptimizationExclusionOptions? exclude,
String? key,
WaypointOptimizationSequencingObjective? optimizeSequencingFor,
WaypointOptimizationOriginOptions? originOptions,
WaypointOptimizationTrafficOptions? traffic,
WaypointOptimizationTravelMode? travelMode,
WaypointOptimizationTravelModeOptions? travelModeOptions,
List<WaypointOptimizationWaypoint>? waypoints,
}) async {
final $query = <String, List<String>>{
if (key != null) 'key': [key],
};
final $payload = <String, dynamic>{
'Origin': origin,
if (avoid != null) 'Avoid': avoid,
if (clustering != null) 'Clustering': clustering,
if (departureTime != null) 'DepartureTime': departureTime,
if (destination != null) 'Destination': destination,
if (destinationOptions != null) 'DestinationOptions': destinationOptions,
if (driver != null) 'Driver': driver,
if (exclude != null) 'Exclude': exclude,
if (optimizeSequencingFor != null)
'OptimizeSequencingFor': optimizeSequencingFor.value,
if (originOptions != null) 'OriginOptions': originOptions,
if (traffic != null) 'Traffic': traffic,
if (travelMode != null) 'TravelMode': travelMode.value,
if (travelModeOptions != null) 'TravelModeOptions': travelModeOptions,
if (waypoints != null) 'Waypoints': waypoints,
};
final response = await _protocol.sendRaw(
payload: $payload,
method: 'POST',
requestUri: '/v2/optimize-waypoints',
queryParams: $query,
exceptionFnMap: _exceptionFns,
);
final $json = await _s.jsonFromResponse(response);
return OptimizeWaypointsResponse(
connections: (($json['Connections'] as List?) ?? const [])
.nonNulls
.map((e) => WaypointOptimizationConnection.fromJson(
e as Map<String, dynamic>))
.toList(),
distance: ($json['Distance'] as int?) ?? 0,
duration: ($json['Duration'] as int?) ?? 0,
impedingWaypoints: (($json['ImpedingWaypoints'] as List?) ?? const [])
.nonNulls
.map((e) => WaypointOptimizationImpedingWaypoint.fromJson(
e as Map<String, dynamic>))
.toList(),
optimizedWaypoints: (($json['OptimizedWaypoints'] as List?) ?? const [])
.nonNulls
.map((e) => WaypointOptimizationOptimizedWaypoint.fromJson(
e as Map<String, dynamic>))
.toList(),
timeBreakdown: WaypointOptimizationTimeBreakdown.fromJson(
($json['TimeBreakdown'] as Map<String, dynamic>?) ??
const <String, dynamic>{}),
pricingBucket: _s.extractHeaderStringValue(
response.headers, 'x-amz-geo-pricing-bucket')!,
);
}