Front-End Web & Mobile

Efficient truck routing with Amazon Location Service

Every day, trucks transport millions of tons of goods across the country, and the efficiency of their routing has a significant impact not only on logistics companies’ bottom line but also on the economy as a whole. Efficient truck routing is an essential component of the transportation and logistics industry, involving strategic planning of the most efficient route for trucks to follow while transporting goods. The primary goal is to reduce distance traveled while ensuring timely deliveries and maximizing resource utilization. By optimizing truck routes, logistics companies can considerably improve the efficiency and profitability of their operations. In this blog post, we will explore the truck routing feature in Amazon Location Service, which utilizes accurate, fresh, and robust data powered by HERE Technologies to help logistics companies achieve their goals. HERE Technologies is an AWS Partner and data provider for Amazon Locations Service. HERE Technologies is a leading location data and technology platform company offering a location-centric platform that is open, secure, and private.

One of the core benefits of efficient truck routing is cost savings. By minimizing the distance that trucks need to travel, logistics companies can reduce fuel costs, limit vehicle wear and tear, and optimize resource utilization. According to a study by the American Transportation Research Institute (ATRI), optimizing truck routes can reduce transportation costs by up to 10%, resulting in significant savings and promoting sustainability by reducing carbon emissions. In addition, the Environmental Protection Agency (EPA) reports that optimizing truck routes can reduce fuel consumption by up to 15%, further promoting sustainability and reducing carbon footprint.

Efficient truck routing also improves delivery times and enhances customer satisfaction. By planning routes that minimize travel time and avoid traffic congestion, logistics companies can ensure that goods are delivered on time and in excellent condition. With the advancement of routing technology, truck routing has become more sophisticated and efficient than ever before. Route optimization services use advanced algorithms that consider traffic patterns, weather conditions, road closures, and other factors to determine the most efficient routes. This technology helps logistics companies save time, resources, and costs, thereby improving their overall operations and enhancing their ability to provide exceptional customer service.

Amazon Location Service sources intelligent routing information and real-time updates through HERE Technologies. It offers a dedicated truck routing feature that takes into account physical restrictions, truck profiles (including height, length, width, and weight), and avoidances like ferries and tolls, to provide truck drivers and operators with safe and efficient routes for their trucks. This ensures that logistics companies can optimize their truck routing, minimize costs, and enhance their overall operations while ensuring the safety and security of their drivers and cargo.

Truck routing scenarios

Trucks have unique attributes that make it necessary to plan their routes differently than regular cars. Factors such as vehicle height, length, weight, width, type of load, and regulatory restrictions must be considered to determine truck-friendly routes. It can be frustrating for drivers when they encounter physical barriers that prevent them from reaching their destination safely, such as low bridges. By using Amazon Location Service’s Routes API powered by HERE Technologies, businesses can optimize routes safely and efficiently, which can help avoid costly fines, dangerous situations, and missed delivery windows. The Amazon Location Service’s Routes API can calculate a route that considers a truck’s attributes and any route limitations, such as low and narrow bridges, hazardous materials, road closures, and tight turns.

For instance, here is a common scenario where we compare the route for a “Regular” delivery van to that of a “Tall” long haul truck. If the destination is Downtown Manhattan, NY from Newark Airport, NJ, the most direct route is through the Holland Tunnel (Figure 1, left). However, the narrow tunnel limits vehicle sizes and prohibits flammable loads. Therefore, tall and hazardous loads must travel nearly twice the distance (53% greater), going south to Staten Island and then across the Verrazano Narrows Bridge, through Brooklyn, and across the Manhattan Bridge (Figure 1, right).

A route that a regular truck (left) and a tall truck (right) takes to go from Newark Airport, NJ to Downtown Manhattan, NY

Figure 1. A route that a regular truck (left) and a tall truck (right) takes to go from Newark Airport, NJ to Downtown Manhattan, NY.

On the other hand, if the destination is Midtown Manhattan, NY, there are two very different routes. One is for regular loads, which go through the Lincoln Tunnel (Figure 2, left), and the other is for tall loads, which may take up to 40 minutes longer (Figure 2, right).

A route that a regular truck (left) and a tall truck (right) takes to go from Newark Airport, NJ to Midtown Manhattan, NY.

Figure 2. A route that a regular truck (left) and a tall truck (right) takes to go from Newark Airport, NJ to Midtown Manhattan, NY.

In the following sections, you will learn how to set up Amazon Location Service resources with HERE Technologies as the data provider and use them in a truck routing application.

Solution overview

You will create the necessary AWS resources using AWS CloudFormation, and configure and deploy a web application using the amazon-location-route-planner project available from the Amazon Location Service’s GitHub repository. The web application is a Vue app that uses Amazon Location Service, as the base map provider and routing engine, MapLibre GL JS, as the map rendering library, and Tailwind CSS, as the UI component library.

The application will have the following components and functionalities:

  • An interactive map specifically designed for truck routing. It will highlight truck restrictions and attributes with symbols and icons, making it easy to identify routes that are safe and efficient for trucks to use.
  • A route calculator that will find the most efficient route based on a number of parameters, such as different transportation modes, departure time, truck dimensions, restrictions, and avoidances. This will help truck drivers and operators plan their routes more effectively, saving time and resources while ensuring that their trucks stay within legal and safety limits.
A web application with an interactive map and routing functionality.

Figure 3. A web application with an interactive map and routing functionality.

Walkthrough

Prerequisites

To complete this walkthrough, you will need access to an AWS account with sufficient permissions to create AWS resources. Create an AWS account if you do not have one already.

Create AWS resources

You will use an AWS CloudFormation template to create a number of AWS resources, including Amazon Location Service map and route calculator resources with HERE Technologies as the data provider. It will also create an Amazon Cognito Identity Pool, and several IAM roles and policies to grant the application the necessary permissions to access Amazon Location Service resources, while maintaining control over who has access to these resources and what actions they can perform.

Click this link to deploy this template into your AWS account. It will open the AWS Management Console and initiate the CloudFormation template deployment process. Check the I acknowledge that AWS CloudFormation might create IAM resources box (Figure 4); then select the Create stack button.

Deploy the CloudFormation template to your AWS account using the AWS CloudFormation console.

Figure 4. Deploy the CloudFormation template to your AWS account using the AWS CloudFormation console.

Once the deployment process is complete, go to the Outputs section to get the Cognito Identity Pool ID (Figure 5).

Access the CloudFormation stack outputs in the AWS CloudFormation console.

Figure 5. Access the CloudFormation stack outputs in the AWS CloudFormation console.

Configure and launch the application

Clone the amazon-location-route-planner project available from the Amazon Location Service’s GitHub repository. Then, navigate to the project directory and install dependencies.

git clone https://github.com/aws-samples/amazon-location-samples.git
cd amazon-location-samples/amazon-location-route-planner/
npm install

Next, open src/config.js and use the CloudFormation stack outputs to enter your Cognito Identity Pool ID.

const identityPoolId = "IDENTITY_POOL_ID";
const mapName = "TruckDemoMap";
const routeCalculatorName = "TruckDemoRouteCalculator";

export { identityPoolId, mapName, routeCalculatorName };

Save your project and run the following command to run the application.

npm run dev

If you open http://localhost:8080/ in your web browser, you will be able to access the interactive map with routing functionality. The map is powered by data from HERE Technologies, as shown in Figure 6.

A web application with an interactive map and routing functionality.

Figure 6. A web application with an interactive map and routing functionality.

Use the application

To use the application, you will need to specify the origin, destination, and optionally up to 23 stops along the way (or waypoints) by clicking on the map. The application will then form a HTTP POST request and call the CalculateRoute operation from the Amazon Location Routes API. The following is an example request body.

{
   "DepartNow":true,
   "DeparturePosition":[
      "-114.15901",
      "51.13882"
   ],
   "DestinationPosition":[
      "-114.16132",
      "51.13349"
   ],
   "DistanceUnit":"Kilometers",
   "IncludeLegGeometry":true,
   "TravelMode":"Truck",
   "TruckModeOptions":{
      "AvoidFerries":false,
      "AvoidTolls":true,
      "Dimensions":{
         "Height":"2.5",
         "Length":"8",
         "Unit":"Meters",
         "Width":"2.5"
      },
      "Weight":{
         "Total":"10000",
         "Unit":"Kilograms"
      }
   },
   "WaypointPositions":[
      [
         "-114.16315",
         "51.13592"
      ]
   ]
}

The API will calculate the optimal route between the origin and destination and return the travel time, distance, and route geometry. You can also configure various parameters such as the transportation mode, unit of measurement, departure time, avoidances, and vehicle profile when selecting truck as the transportation mode. After parsing the API response, the web application will display the results. The following is an example API response.

{
   "Legs":[
      {
         "StartPosition":[
            -114.1590122,
            51.1388477
         ],
         "EndPosition":[
            -114.1632184,
            51.135898
         ],
         "Distance":0.641,
         "DurationSeconds":78,
         "Geometry":{
            "LineString":[
               [
                  -114.159012,
                  51.138848
               ],
               ...
               [
                  -114.163218,
                  51.135898
               ]
            ]
         },
         "Steps":[
            {
               "StartPosition":[
                  -114.159012,
                  51.138848
               ],
               "EndPosition":[
                  -114.16424,
                  51.13778
               ],
               "Distance":0.391,
               "DurationSeconds":35,
               "GeometryOffset":0
            },
            {
               "StartPosition":[
                  -114.16424,
                  51.13778
               ],
               "EndPosition":[
                  -114.163218,
                  51.135898
               ],
               "Distance":0.25,
               "DurationSeconds":43,
               "GeometryOffset":11
            }
         ]
      },
      {
         "StartPosition":[
            -114.1632184,
            51.135898
         ],
         "EndPosition":[
            -114.1614708,
            51.1334579
         ],
         "Distance":0.298,
         "DurationSeconds":19,
         "Geometry":{
            "LineString":[
               [
                  -114.163218,
                  51.135898
               ],
               ...
               [
                  -114.161471,
                  51.133458
               ]
            ]
         },
         "Steps":[
            {
               "StartPosition":[
                  -114.163218,
                  51.135898
               ],
               "EndPosition":[
                  -114.161471,
                  51.133458
               ],
               "Distance":0.298,
               "DurationSeconds":19,
               "GeometryOffset":0
            }
         ]
      }
   ],
   "Summary":{
      "RouteBBox":[
         -114.16462,
         51.1334579,
         -114.159012,
         51.138848
      ],
      "DataSource":"Here",
      "Distance":0.9390000000000001,
      "DurationSeconds":97,
      "DistanceUnit":"Kilometers"
   }
}

Clean up

If you would like to remove all of the resources created in this walkthrough, delete the CloudFormation stack called amazon-location-route-planner (Figure 7).

Use the AWS CloudFormation console to delete all the resources created in this walkthrough.

Figure 7. Use the AWS CloudFormation console to delete all the resources created in this walkthrough.

Conclusion

With Amazon Location Service, businesses can leverage powerful routing algorithms and real-time data to create efficient routes that take into account truck profiles (including height, length, width, and weight), physical restrictions, traffic information, and avoidances to provide truck drivers and operators with safe and efficient routes for their trucks. In this post, you learned how to use Amazon Location Service to add an interactive map and route calculator specifically designed for truck routing to a web application, with high-quality data from HERE Technologies.

There are several sample projects on Amazon Location Service’s GitHub repository that you can explore to learn how to build applications with location data and functionality on AWS. Visit Amazon Location Service’s product page to learn about the offerings, common use cases, and customer success stories. To dive deeper into Amazon Location Service’s features, visit the developer documentation.

About the authors:

Abraham Poorazizi

Abraham Poorazizi is a Senior Developer Advocate at AWS. He is passionate about creating digital solutions to solve real-world problems. He spends his time working with developers to help them build successful products with Amazon Location Service.

Erwin Soekianto

Erwin Soekianto is a Senior Developer Evangelist at HERE Technologies. He has a passion for maps, technology and helping others. He seeks to empower the developer community by driving awareness and adoption of HERE Technologies.

Anand Vijayan

Anand Vijayan works as a Senior Product Manager focusing on Amazon Location Service at AWS. He is excited about geospatial technologies and enjoys helping customers solve complex problems at scale leveraging the power of the cloud. He is an avid astronomer and has a keen interest in all things space.