Skip to content

calculate_route async

calculate_route(
    calculator_name: ResourceName,
    departure_position: Position,
    destination_position: Position,
    *,
    config_overrides: Optional[AsyncLocationClientConfig] = None,
    waypoint_positions: Optional[WaypointPositionList] = None,
    travel_mode: Optional[TravelMode] = None,
    departure_time: Optional[Timestamp] = None,
    depart_now: Optional[SensitiveBoolean] = None,
    distance_unit: Optional[DistanceUnit] = None,
    include_leg_geometry: Optional[SensitiveBoolean] = None,
    car_mode_options: Optional[CalculateRouteCarModeOptions] = None,
    truck_mode_options: Optional[CalculateRouteTruckModeOptions] = None,
    arrival_time: Optional[Timestamp] = None,
    optimize_for: Optional[OptimizationMode] = None,
    key: Optional[ApiKey] = None,
) -> CalculateRouteResponse

This operation is no longer current and may be deprecated in the future. We recommend you upgrade to CalculateRoutes or CalculateIsolines unless you require Grab data.

  • CalculateRoute is part of a previous Amazon Location Service Routes API (version 1) which has been superseded by a more intuitive, powerful, and complete API (version 2).

  • The version 2 CalculateRoutes operation gives better results for point-to-point routing, while the version 2 CalculateIsolines operation adds support for calculating service areas and travel time envelopes.

  • If you are using an Amazon Web Services SDK or the Amazon Web Services CLI, note that the Routes API version 2 is found under geo-routes or geo_routes, not under location.

  • Since Grab is not yet fully supported in Routes API version 2, we recommend you continue using API version 1 when using Grab.

Calculates a route given the following required parameters: DeparturePosition and DestinationPosition. 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 the route.

Additional options include:

  • Specifying a departure time using either DepartureTime or DepartNow. This calculates a route based on predictive traffic data at the given time.

    You can't specify both DepartureTime and DepartNow in a single request. Specifying both parameters returns a validation error.

  • 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.

    If you specify walking for the travel mode and your data provider is Esri, the start and destination must be within 40km.

Parameters:

  • calculator_name (ResourceName) –

    The name of the route calculator resource that you want to use to calculate the route.

  • departure_position (Position) –

    The start position for the route. Defined in World Geodetic System (WGS 84) format: [longitude, latitude].

    • For example, [-123.115, 49.285]

    If you specify a departure that's not located on a road, Amazon Location moves the position to the nearest road. If Esri is the provider for your route calculator, specifying a route that is longer than 400 km returns a 400 RoutesValidationException error.

    Valid Values: [-180 to 180,-90 to 90]

  • destination_position (Position) –

    The finish position for the route. Defined in World Geodetic System (WGS 84) format: [longitude, latitude].

    • For example, [-122.339, 47.615]

    If you specify a destination that's not located on a road, Amazon Location moves the position to the nearest road.

    Valid Values: [-180 to 180,-90 to 90]

  • waypoint_positions (Optional[WaypointPositionList], default: None ) –

    Specifies an ordered list of up to 23 intermediate positions to include along a route between the departure position and destination position.

    • For example, from the DeparturePosition [-123.115, 49.285], the route follows the order that the waypoint positions are given [[-122.757, 49.0021],[-122.349, 47.620]]

    If you specify a waypoint position that's not located on a road, Amazon Location moves the position to the nearest road.

    Specifying more than 23 waypoints returns a 400 ValidationException error.

    If Esri is the provider for your route calculator, specifying a route that is longer than 400 km returns a 400 RoutesValidationException error.

    Valid Values: [-180 to 180,-90 to 90]

  • travel_mode (Optional[TravelMode], default: None ) –

    Specifies the mode of transport when calculating a route. Used in estimating the speed of travel and road compatibility. You can choose Car, Truck, Walking, Bicycle or Motorcycle as options for the TravelMode.

    Bicycle and Motorcycle are only valid when using Grab as a data provider, and only within Southeast Asia.

    Truck is not available for Grab.

    For more details on the using Grab for routing, including areas of coverage, see GrabMaps in the Amazon Location Service Developer Guide.

    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.

    Default Value: Car

  • departure_time (Optional[Timestamp], default: None ) –

    Specifies the desired time of departure. Uses the given time to calculate the route. Otherwise, the best time of day to travel with the best traffic conditions is used to calculate the route.

    • In ISO 8601 format: YYYY-MM-DDThh:mm:ss.sssZ. For example, 2020–07-2T12:15:20.000Z+01:00

  • depart_now (Optional[SensitiveBoolean], default: None ) –

    Sets the time of departure as the current time. Uses the current time to calculate a route. Otherwise, the best time of day to travel with the best traffic conditions is used to calculate the route.

    Default Value: false

    Valid Values: false | true

  • distance_unit (Optional[DistanceUnit], default: None ) –

    Set the unit system to specify the distance.

    Default Value: Kilometers

  • include_leg_geometry (Optional[SensitiveBoolean], default: None ) –

    Set to include the geometry details in the result for each path between a pair of positions.

    Default Value: false

    Valid Values: false | true

  • car_mode_options (Optional[CalculateRouteCarModeOptions], default: None ) –

    Specifies route preferences when traveling by Car, such as avoiding routes that use ferries or tolls.

    Requirements: TravelMode must be specified as Car.

  • truck_mode_options (Optional[CalculateRouteTruckModeOptions], default: None ) –

    Specifies route preferences when traveling by Truck, such as avoiding routes that use ferries or tolls, and truck specifications to consider when choosing an optimal road.

    Requirements: TravelMode must be specified as Truck.

  • arrival_time (Optional[Timestamp], default: None ) –

    Specifies the desired time of arrival. Uses the given time to calculate the route. Otherwise, the best time of day to travel with the best traffic conditions is used to calculate the route.

    ArrivalTime is not supported Esri.

  • optimize_for (Optional[OptimizationMode], default: None ) –

    Specifies the distance to optimize for when calculating a route.

  • key (Optional[ApiKey], default: None ) –

    The optional API key to authorize the request.

Raises:

  • AccessDeniedException –

    The request was denied because of insufficient access or permissions. Check with an administrator to verify your permissions.

  • InternalServerException –

    The request has failed to process because of an unknown server error, exception, or failure.

  • ResourceNotFoundException –

    The resource that you've entered was not found in your AWS account.

  • ThrottlingException –

    The request was denied because of request throttling.

  • ValidationException –

    The input failed to meet the constraints specified by the AWS service.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_location/_services/async_location.py
async def calculate_route(
    self,
    calculator_name: "capo_location.types.resource_name.ResourceName",
    departure_position: "capo_location.types.position.Position",
    destination_position: "capo_location.types.position.Position",
    *,
    config_overrides: Optional[AsyncLocationClientConfig] = None,
    waypoint_positions: Optional[
        "capo_location.types.waypoint_position_list.WaypointPositionList"
    ] = None,
    travel_mode: Optional["capo_location.types.travel_mode.TravelMode"] = None,
    departure_time: Optional["capo_location.types.timestamp.Timestamp"] = None,
    depart_now: Optional[
        "capo_location.types.sensitive_boolean.SensitiveBoolean"
    ] = None,
    distance_unit: Optional[
        "capo_location.types.distance_unit.DistanceUnit"
    ] = None,
    include_leg_geometry: Optional[
        "capo_location.types.sensitive_boolean.SensitiveBoolean"
    ] = None,
    car_mode_options: Optional[
        "capo_location.types.calculate_route_car_mode_options.CalculateRouteCarModeOptions"
    ] = None,
    truck_mode_options: Optional[
        "capo_location.types.calculate_route_truck_mode_options.CalculateRouteTruckModeOptions"
    ] = None,
    arrival_time: Optional["capo_location.types.timestamp.Timestamp"] = None,
    optimize_for: Optional[
        "capo_location.types.optimization_mode.OptimizationMode"
    ] = None,
    key: Optional["capo_location.types.api_key.ApiKey"] = None,
) -> "capo_location.types.calculate_route_response.CalculateRouteResponse":
    """<important> <p>This operation is no longer current and may be deprecated in the future. We recommend you upgrade to <a href="/location/latest/APIReference/API_CalculateRoutes.html"> <code>CalculateRoutes</code> </a> or <a href="/location/latest/APIReference/API_CalculateIsolines.html"> <code>CalculateIsolines</code> </a> unless you require Grab data.</p> <ul> <li> <p> <code>CalculateRoute</code> is part of a previous Amazon Location Service Routes API (version 1) which has been superseded by a more intuitive, powerful, and complete API (version 2).</p> </li> <li> <p>The version 2 <code>CalculateRoutes</code> operation gives better results for point-to-point routing, while the version 2 <code>CalculateIsolines</code> operation adds support for calculating service areas and travel time envelopes.</p> </li> <li> <p>If you are using an Amazon Web Services SDK or the Amazon Web Services CLI, note that the Routes API version 2 is found under <code>geo-routes</code> or <code>geo_routes</code>, not under <code>location</code>.</p> </li> <li> <p>Since Grab is not yet fully supported in Routes API version 2, we recommend you continue using API version 1 when using Grab.</p> </li> </ul> </important> <p> <a href="https://docs.aws.amazon.com/location/previous/developerguide/calculate-route.html">Calculates a route</a> given the following required parameters: <code>DeparturePosition</code> and <code>DestinationPosition</code>. Requires that you first <a href="https://docs.aws.amazon.com/location-routes/latest/APIReference/API_CreateRouteCalculator.html">create a route calculator resource</a>.</p> <p>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 the route.</p> <p>Additional options include:</p> <ul> <li> <p> <a href="https://docs.aws.amazon.com/location/previous/developerguide/departure-time.html">Specifying a departure time</a> using either <code>DepartureTime</code> or <code>DepartNow</code>. This calculates a route based on predictive traffic data at the given time. </p> <note> <p>You can't specify both <code>DepartureTime</code> and <code>DepartNow</code> in a single request. Specifying both parameters returns a validation error.</p> </note> </li> <li> <p> <a href="https://docs.aws.amazon.com/location/previous/developerguide/travel-mode.html">Specifying a travel mode</a> using TravelMode sets the transportation mode used to calculate the routes. This also lets you specify additional route preferences in <code>CarModeOptions</code> if traveling by <code>Car</code>, or <code>TruckModeOptions</code> if traveling by <code>Truck</code>.</p> <note> <p>If you specify <code>walking</code> for the travel mode and your data provider is Esri, the start and destination must be within 40km.</p> </note> </li> </ul>

    Args:
        calculator_name: <p>The name of the route calculator resource that you want to use to calculate the route. </p>
        departure_position: <p>The start position for the route. Defined in <a href="https://earth-info.nga.mil/index.php?dir=wgs84&amp;action=wgs84">World Geodetic System (WGS 84)</a> format: <code>[longitude, latitude]</code>.</p> <ul> <li> <p>For example, <code>[-123.115, 49.285]</code> </p> </li> </ul> <note> <p>If you specify a departure that's not located on a road, Amazon Location <a href="https://docs.aws.amazon.com/location/previous/developerguide/snap-to-nearby-road.html">moves the position to the nearest road</a>. If Esri is the provider for your route calculator, specifying a route that is longer than 400 km returns a <code>400 RoutesValidationException</code> error.</p> </note> <p>Valid Values: <code>[-180 to 180,-90 to 90]</code> </p>
        destination_position: <p>The finish position for the route. Defined in <a href="https://earth-info.nga.mil/index.php?dir=wgs84&amp;action=wgs84">World Geodetic System (WGS 84)</a> format: <code>[longitude, latitude]</code>.</p> <ul> <li> <p> For example, <code>[-122.339, 47.615]</code> </p> </li> </ul> <note> <p>If you specify a destination that's not located on a road, Amazon Location <a href="https://docs.aws.amazon.com/location/previous/developerguide/snap-to-nearby-road.html">moves the position to the nearest road</a>. </p> </note> <p>Valid Values: <code>[-180 to 180,-90 to 90]</code> </p>
        waypoint_positions: <p>Specifies an ordered list of up to 23 intermediate positions to include along a route between the departure position and destination position. </p> <ul> <li> <p>For example, from the <code>DeparturePosition</code> <code>[-123.115, 49.285]</code>, the route follows the order that the waypoint positions are given <code>[[-122.757, 49.0021],[-122.349, 47.620]]</code> </p> </li> </ul> <note> <p>If you specify a waypoint position that's not located on a road, Amazon Location <a href="https://docs.aws.amazon.com/location/previous/developerguide/snap-to-nearby-road.html">moves the position to the nearest road</a>. </p> <p>Specifying more than 23 waypoints returns a <code>400 ValidationException</code> error.</p> <p>If Esri is the provider for your route calculator, specifying a route that is longer than 400 km returns a <code>400 RoutesValidationException</code> error.</p> </note> <p>Valid Values: <code>[-180 to 180,-90 to 90]</code> </p>
        travel_mode: <p>Specifies the mode of transport when calculating a route. Used in estimating the speed of travel and road compatibility. You can choose <code>Car</code>, <code>Truck</code>, <code>Walking</code>, <code>Bicycle</code> or <code>Motorcycle</code> as options for the <code>TravelMode</code>.</p> <note> <p> <code>Bicycle</code> and <code>Motorcycle</code> are only valid when using Grab as a data provider, and only within Southeast Asia.</p> <p> <code>Truck</code> is not available for Grab.</p> <p>For more details on the using Grab for routing, including areas of coverage, see <a href="https://docs.aws.amazon.com/location/previous/developerguide/grab.html">GrabMaps</a> in the <i>Amazon Location Service Developer Guide</i>.</p> </note> <p>The <code>TravelMode</code> you specify also determines how you specify route preferences: </p> <ul> <li> <p>If traveling by <code>Car</code> use the <code>CarModeOptions</code> parameter.</p> </li> <li> <p>If traveling by <code>Truck</code> use the <code>TruckModeOptions</code> parameter.</p> </li> </ul> <p>Default Value: <code>Car</code> </p>
        departure_time: <p>Specifies the desired time of departure. Uses the given time to calculate the route. Otherwise, the best time of day to travel with the best traffic conditions is used to calculate the route.</p> <ul> <li> <p>In <a href="https://www.iso.org/iso-8601-date-and-time-format.html">ISO 8601</a> format: <code>YYYY-MM-DDThh:mm:ss.sssZ</code>. For example, <code>2020–07-2T12:15:20.000Z+01:00</code> </p> </li> </ul>
        depart_now: <p>Sets the time of departure as the current time. Uses the current time to calculate a route. Otherwise, the best time of day to travel with the best traffic conditions is used to calculate the route.</p> <p>Default Value: <code>false</code> </p> <p>Valid Values: <code>false</code> | <code>true</code> </p>
        distance_unit: <p>Set the unit system to specify the distance.</p> <p>Default Value: <code>Kilometers</code> </p>
        include_leg_geometry: <p>Set to include the geometry details in the result for each path between a pair of positions.</p> <p>Default Value: <code>false</code> </p> <p>Valid Values: <code>false</code> | <code>true</code> </p>
        car_mode_options: <p>Specifies route preferences when traveling by <code>Car</code>, such as avoiding routes that use ferries or tolls.</p> <p>Requirements: <code>TravelMode</code> must be specified as <code>Car</code>.</p>
        truck_mode_options: <p>Specifies route preferences when traveling by <code>Truck</code>, such as avoiding routes that use ferries or tolls, and truck specifications to consider when choosing an optimal road.</p> <p>Requirements: <code>TravelMode</code> must be specified as <code>Truck</code>.</p>
        arrival_time: <p>Specifies the desired time of arrival. Uses the given time to calculate the route. Otherwise, the best time of day to travel with the best traffic conditions is used to calculate the route.</p> <note> <p>ArrivalTime is not supported Esri.</p> </note>
        optimize_for: <p>Specifies the distance to optimize for when calculating a route.</p>
        key: <p>The optional <a href="https://docs.aws.amazon.com/location/previous/developerguide/using-apikeys.html">API key</a> to authorize the request.</p>

    Raises:
        capo_location.errors.access_denied_exception.AccessDeniedException: <p>The request was denied because of insufficient access or permissions. Check with an administrator to verify your permissions.</p>
        capo_location.errors.internal_server_exception.InternalServerException: <p>The request has failed to process because of an unknown server error, exception, or failure.</p>
        capo_location.errors.resource_not_found_exception.ResourceNotFoundException: <p>The resource that you've entered was not found in your AWS account.</p>
        capo_location.errors.throttling_exception.ThrottlingException: <p>The request was denied because of request throttling.</p>
        capo_location.errors.validation_exception.ValidationException: <p>The input failed to meet the constraints specified by the AWS service. </p>
        capo_location.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_location.types.calculate_route_request.CalculateRouteRequest]",
    ) -> AsyncOperationResponse[
        "capo_location.types.calculate_route_response.CalculateRouteResponse"
    ]:
        import capo_location._operations.location_service.calculate_route

        (
            output,
            http_response,
        ) = await capo_location._operations.location_service.calculate_route.async_calculate_route(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_location.types.calculate_route_request.CalculateRouteRequest",
    ) -> dict[str, Any]:
        import capo_location.types.calculate_route_request

        return capo_location.types.calculate_route_request.redact_sensitive(input_)

    def _redact_output(
        output: "capo_location.types.calculate_route_response.CalculateRouteResponse",
    ) -> dict[str, Any]:
        import capo_location.types.calculate_route_response

        return capo_location.types.calculate_route_response.redact_sensitive(output)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CalculateRoute",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_location.types.calculate_route_request.CalculateRouteRequest = {
        "calculator_name": calculator_name,
        "departure_position": departure_position,
        "destination_position": destination_position,
    }
    if waypoint_positions is not None:
        input_["waypoint_positions"] = waypoint_positions
    if travel_mode is not None:
        input_["travel_mode"] = travel_mode
    if departure_time is not None:
        input_["departure_time"] = departure_time
    if depart_now is not None:
        input_["depart_now"] = depart_now
    if distance_unit is not None:
        input_["distance_unit"] = distance_unit
    if include_leg_geometry is not None:
        input_["include_leg_geometry"] = include_leg_geometry
    if car_mode_options is not None:
        input_["car_mode_options"] = car_mode_options
    if truck_mode_options is not None:
        input_["truck_mode_options"] = truck_mode_options
    if arrival_time is not None:
        input_["arrival_time"] = arrival_time
    if optimize_for is not None:
        input_["optimize_for"] = optimize_for
    if key is not None:
        input_["key"] = key

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output