Optimize delivery routes for carriers from Google Sheets using Google Maps
This workflow automates the process of converting delivery addresses into geographic coordinates and optimizes delivery routes for each carrier using Google Maps.
Finally, the workflow outputs an optimized circular route that starts and ends at the base location.
This workflow is particularly useful for:
Logistics companies Courier services Delivery businesses Field service operations Fleet management teams
It enables faster route planning, improves delivery efficiency, and provides a low-code automation solution that integrates directly with existing operational spreadsheets.
Key Advantages
- ✅ Automated Address Geocoding
The workflow automatically converts delivery addresses into precise GPS coordinates using Google Maps APIs, eliminating manual data entry and reducing human errors.
- ✅ Delivery Route Optimization
By calculating the most efficient delivery order, the workflow helps drivers reduce travel time, fuel consumption, and operational costs.
- ✅ Seamless Google Sheets Integration
All delivery data is managed directly inside Google Sheets, making the system easy to use for logistics teams without requiring additional software.
- ✅ Carrier-Based Delivery Grouping
Deliveries are automatically grouped by carrier, allowing each driver or logistics operator to receive a dedicated optimized route.
- ✅ Real-Time Data Processing
The workflow dynamically processes only the deliveries scheduled for the current day, ensuring routes are always updated and relevant.
- ✅ Scalable and Flexible
The solution can easily scale to handle larger delivery volumes and can be adapted for different logistics operations, territories, or business models.
- ✅ Reduced Operational Costs
Optimized routes reduce unnecessary mileage, helping companies lower fuel expenses, vehicle wear, and delivery times.
- ✅ Intelligent Distance Calculation
The workflow uses Google Routes API for accurate driving distances and includes fallback logic to ensure continuity even if API responses fail.
- ✅ Fully Automated Workflow
Once configured, the entire process runs automatically with minimal manual intervention, improving productivity and operational reliability.
- ✅ Easy Customization
The workflow can be customized to support:
Multiple warehouses Dynamic starting points Additional delivery constraints Traffic-aware routing Advanced optimization strategies
How it works
Manual trigger
The workflow starts manually by clicking "Execute workflow".
Fetch today’s deliveries
Reads from a Google Sheet.
Filters rows where DATE DELIVERY equals today’s date.
Geocode each delivery address
Loops through each delivery row.
Calls the Google Maps Places API (textsearch) to get latitude and longitude.
Updates the sheet’s LANG and LONG columns.
Marks DONE = "x" to avoid reprocessing.
Get start address location
A fixed start address (e.g., warehouse) is geocoded once.
Stores START ADDRESS, START LAT, START LNG.
Filter already processed deliveries
Reads the sheet again, filtering for today’s date and DONE = "x".
These are fully geocoded deliveries ready for routing.
Group deliveries by carrier
Groups all delivery rows by NAME CARRIER.
Optimize route for each carrier
Runs a custom JavaScript routing algorithm:
Uses Google Routes API for real driving distances.
Implements a nearest neighbor heuristic + 2-opt optimization.
Computes a circular route starting/ending at the warehouse.
Outputs an ordered list of stops including the warehouse as start and end.
Return optimized route
The final route is returned as structured JSON.
Can be further used for writing back to Sheets or displaying.
Set up steps
Google Sheets setup
Create a Google Sheet with columns:
row_number, NAME CARRIER, DATE DELIVERY, ADDRESS, LANG, LONG, DONE.
Clone the example sheet.
Note the documentId from the sheet’s URL.
Google Sheets OAuth2 credentials
In n8n, add a Google Sheets OAuth2 API credential.
Use the same email that owns/edits the sheet.
Google Maps API credentials
Enable Places API and Routes API in Google Cloud Console.
Create an API key with no restrictions or restrict it to the required APIs.
In n8n, add an HTTP Query Auth credential:
Key: key
Value: your Google Maps API key.
Update workflow configuration
In the Google Sheets nodes (Get date delivery, Update Lat and Lng, Get addresses), replace the documentId with your own sheet ID.
Ensure the sheet name (Foglio1 or gid=0) matches.
Set start address
In the Start address node (n8n-nodes-base.set), edit the START ADDRESS assignment to your warehouse/starting location.
Adjust wait time
The Wait node is set to 10 seconds to respect Google Maps API rate limits. Adjust if needed.
Run the workflow
Click "When clicking ‘Execute workflow’" button in n8n.
The workflow geocodes new addresses, updates the sheet, and outputs an optimized route per carrier.
👉 Subscribe to my new YouTube channel. Here I’ll share videos and Shorts with practical tutorials and FREE templates for n8n.
Need help customizing?
Contact me for consulting and support or add me on Linkedin.
Related Templates
Extract Title tag and Meta description from url for SEO analysis with Airtable
Extract Title tag and meta description from url for SEO analysis. How it works The workflows takes records from Airtabl...
Restore your workflows from GitHub
This workflow restores all n8n instance workflows from GitHub backups using the n8n API node. It complements the Backup ...
Extract Named Entities from Web Pages with Google Natural Language API
Who is this for? Content strategists analyzing web page semantic content SEO professionals conducting entity-based anal...
🔒 Please log in to import templates to n8n and favorite templates
Workflow Visualization
Loading...
Preparing workflow renderer
Comments (0)
Login to post comments