pythonamazon-web-servicesroutesboto3calculator

AWS Route Calculator API/ Here Maps


I am using AWS Location Services Route Calculator to determine travel time and travel distance of several origin destination pairs. The code is working but it is not reflecting travel delay due to traffic. It calculates the difference between two cities with departure time at 2 AM and 11 AM are only a couple minutes of time difference. Doing the same search manually in Here Maps shows the same times but the 11 am departure time shows a significant delay like +40 minutes probably due to traffic. Is this data available in the AWS api?

Town1   Town2       Mile 2  Mile 8  Mile 16 Mile 23 Time 2  Time 8  Time 16 Time 23
ACTON   CHARLEMONT  86.56   86.56   87.98   87.98   103.68  103.89  104.95  104.31
ACTON   CHARLESTOWN 23.43   23.43   22.98   23.43   38.09   38.14   44.33   42.89


def initialize_amazon_client(aws_access_key_id, aws_secret_access_key):
    """Initialize and return an Amazon Location Service client."""
    session = boto3.Session(
        aws_access_key_id=aws_access_key_id,
        aws_secret_access_key=aws_secret_access_key,
        region_name='us-east-1'
    )

    return session.client('location')


client = initialize_amazon_client(aws_access_key_id, aws_secret_access_key)


response = client.calculate_route(
        CalculatorName=calculator_name,
        DeparturePosition=origin,
        DestinationPosition=destination,
        TravelMode='Car',
        DepartNow=False,
        DepartureTime=departure_time,
        DistanceUnit='Miles',
        CarModeOptions={
            'AvoidFerries': False,
            'AvoidTolls': False
        }
    )

Solution

  • From Routes - Amazon Location Service:

    Traffic and departure time

    The Amazon Location Service takes traffic into account when calculating a route. The trafffic that it considers is based on the time that you specify. You can specify to depart now, or you can provide a specific time that you want to leave, which will affect the route result by adjusting for traffic at the specified time.

    And from Departure time - Amazon Location Service:

    You can set a specific a departure time to use live and predictive traffic conditions from your chosen data provider, by using one of the following options:

    DepartNow – When set to true, it uses live traffic conditions to calculate the fastest travel path.

    DepartureTime – When provided, it uses predictive and known traffic conditions for the requested time. Defined in the following format: YYYY-MM-DDThh:mm:ss.sssZ

    So, it seems that live traffic will only be used if you are estimating route 'now'. Otherwise, it is 'expected' traffic levels.