Get Route Distance
Calculates the driving distance between two geographic coordinates using Google Maps Directions API.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- Coordinate 1 - Starting geographic coordinate in "latitude,longitude" format (e.g., "41.0082,28.9784").
- Coordinate 2 - Ending geographic coordinate in "latitude,longitude" format (e.g., "40.7128,74.0060").
Options
- Credentials - Google Maps API key credential used to authenticate with the service.
Output
- Distance - The driving route distance between the two coordinates in kilometers.
How It Works
The Get Route Distance node calculates the actual driving distance between two geographic coordinates using Google Maps Directions API. When executed, the node:
- Validates both coordinate inputs
- Parses the latitude and longitude values from each coordinate string
- Retrieves the Google Maps API key from credentials
- Creates a Directions request with the provided coordinates
- Sends the request to Google Maps Directions API
- Calculates the total route distance by summing the distance of all route legs
- Returns the distance in kilometers
Requirements
- A valid Google Maps API key with Directions API enabled
- Two valid geographic coordinates in "latitude,longitude" format
Error Handling
The node will return specific errors in the following cases:
- Empty or invalid Coordinate 1 input
- Empty or invalid Coordinate 2 input
- Invalid or missing Google Maps API credentials
- Incorrect coordinate format (missing comma or invalid numbers)
- Non-numeric latitude or longitude values
- Google Maps API service errors
- Network connectivity issues
- No route found between the coordinates
Practical Examples
Example 1: Calculate Driving Distance Between Two Addresses
Find the actual road distance for a delivery route:
Input:
- Coordinate 1:
"40.7128,-74.0060"(New York City) - Coordinate 2:
"40.7589,-73.9851"(Times Square) - Credentials: Your Google Maps API key
Output:
- Distance:
6.2(kilometers)
Compare to straight-line:
- Calculate Distance (straight-line): ~4.5 km
- Get Route Distance (driving): ~6.2 km
- Difference accounts for road network
Example 2: Delivery Route Optimization
Calculate driving distances for multiple delivery stops:
Workflow:
- Address to Coordinates - Convert warehouse address
- Address:
"123 Warehouse St, City" - Output:
{{warehouseCoords}}="{{result.geometry.location.lat}},{{result.geometry.location.lng}}"
- Address:
- Read Excel - Load customer delivery addresses
- Loop - For each customer
- Address to Coordinates - Get customer coordinates
- Address:
{{customer.address}} - Output:
{{customerCoords}}="{{result.geometry.location.lat}},{{result.geometry.location.lng}}"
- Address:
- Get Route Distance - Calculate driving distance
- Coordinate 1:
{{warehouseCoords}} - Coordinate 2:
{{customerCoords}}
- Coordinate 1:
- Set Variable - Store distance
{{customer.driveDistance}}={{distance}}
- Sort - Order by shortest distance first
- Write Excel - Save optimized route
Example 3: Shipping Cost Calculator
Calculate shipping costs based on driving distance:
Input:
- Coordinate 1:
"34.0522,-118.2437"(LA warehouse) - Coordinate 2:
{{deliveryLocation}}(customer location)
Workflow:
- Get Route Distance - Get driving distance
- Set Variable - Calculate shipping cost
{{baseCost}} = 10 // Base fee
{{perKmCost}} = 2 // Cost per kilometer
{{shippingCost}} = {{baseCost}} + ({{distance}} * {{perKmCost}}) - Return - Total shipping cost
Example:
- Distance: 25 km
- Shipping Cost: $10 + (25 × $2) = $60
Example 4: Service Area Validation
Check if a location is within delivery radius:
Scenario: Only deliver within 50km driving distance
Workflow:
- Set Variable - Service center location
{{centerCoords}}="41.8781,-87.6298"(Chicago)
- Get Route Distance - Calculate driving distance
- Coordinate 1:
{{centerCoords}} - Coordinate 2:
{{customerCoords}}
- Coordinate 1:
- Condition - Check service area
- If
{{distance}}5 or less0:- Status: "In Service Area"
- Estimated delivery time:
{{distance / 40}}hours (avg 40 km/hr)
- Else:
- Status: "Out of Service Area"
- Message: "We don't deliver to your location"
- If
Example 5: Multi-Stop Route Distance
Calculate total distance for a route with multiple stops:
Excel Structure:
| Stop | Address | Latitude | Longitude | Distance to Next |
|---|---|---|---|---|
| 1 | Start | 40.7128 | -74.0060 | |
| 2 | Stop A | 40.7589 | -73.9851 | |
| 3 | Stop B | 40.7489 | -73.9680 | |
| 4 | End | 40.7128 | -74.0060 |
Workflow:
- Read Excel - Load route stops
- Loop - For each stop (except last)
- Index:
{{i}}
- Index:
- Set Variable - Current and next coordinates
{{current}}="{{stops[i].lat}},{{stops[i].lng}}"{{next}}="{{stops[i+1].lat}},{{stops[i+1].lng}}"
- Get Route Distance
- Coordinate 1:
{{current}} - Coordinate 2:
{{next}}
- Coordinate 1:
- Set Variable - Store leg distance
{{stops[i].distanceToNext}}={{distance}}
- Calculate - Sum all distances
{{totalDistance}}= sum of alldistanceToNextvalues
- Write Excel - Save route with distances
Example 6: Compare Multiple Routes
Find the shortest driving route from one location to multiple destinations:
Input:
- Origin:
"51.5074,-0.1278"(London) - Destinations: Array of coordinates
Workflow:
- Set Variable - Destination list
{{destinations}} = [
{ name: "Paris", coords: "48.8566,2.3522" },
{ name: "Amsterdam", coords: "52.3676,4.9041" },
{ name: "Brussels", coords: "50.8503,4.3517" }
] - Loop - Check each destination
- Get Route Distance
- Coordinate 1:
{{origin}} - Coordinate 2:
{{item.coords}}
- Coordinate 1:
- Set Variable - Store distance
{{item.distance}}={{distance}}
- Find Minimum - Get shortest route
- Return - Recommended destination
Tips for Effective Use
Route Distance vs Straight-Line Distance
Calculate Distance (Haversine):
- Straight-line "as the crow flies"
- No API call required
- Fast and free
- Good for initial filtering
Get Route Distance (Directions API):
- Actual driving distance
- Requires API key and quota
- More accurate for logistics
- Accounts for road network
Best Practice: Use Both
- Use Calculate Distance to filter (e.g., within 100km straight-line)
- Use Get Route Distance for filtered results (actual driving distance)
- This saves API quota and improves performance
Understanding the Route Calculation
The Directions API:
- Finds the optimal driving route between coordinates
- Considers road networks and restrictions
- Accounts for one-way streets
- Respects turn restrictions
- Uses current road data (not real-time traffic)
What it includes:
- All roads and highways
- Necessary turns and intersections
- Legal driving routes
What it does NOT include (by default):
- Real-time traffic conditions
- Toll roads preference
- Alternative routes
- Waypoints or stops
Coordinate Format Requirements
Format: "latitude,longitude" as a single string
- Correct:
"40.7128,-74.0060" - Correct:
"40.7128, -74.0060"(spaces trimmed)
Build from separate values:
// From variables
{{latitude + "," + longitude}}
// From geocoding result
{{result.geometry.location.lat + "," + result.geometry.location.lng}}
Performance and Cost Optimization
API Quota Management:
- Directions API calls count against your quota
- Default free tier: ~40,000 requests/month
- Monitor usage in Google Cloud Console
- Consider caching results for frequent routes
Optimization strategies:
-
Cache Results: Store calculated distances in database
- Same route queries use cached value
- Update cache periodically (weekly/monthly)
-
Batch Processing: Add delays between requests
- Use "Delay After" property (e.g., 0.5 seconds)
- Prevents hitting rate limits
-
Pre-filter: Use Calculate Distance first
If straight-line > 100km:
Skip (definitely too far)
Else:
Get Route Distance (check actual distance) -
Smart Caching:
- Cache by coordinate pair (both directions)
- Set cache expiration (roads change)
- Invalidate cache for construction areas
Distance Conversions
Output is in kilometers. Convert as needed:
- To Miles:
{{distance * 0.621371}} - To Meters:
{{distance * 1000}} - Estimated Time (avg 60 km/h):
{{distance / 60}}hours - Estimated Time (avg 40 km/h urban):
{{distance / 40}}hours
Handling Edge Cases
Island or Disconnected Locations:
- Error: "No route found"
- Some locations aren't connected by roads
- Handle gracefully (ferry routes not included)
Very Long Distances:
- International routes work if connected by road
- Example: London to Istanbul works
- Example: New York to London fails (ocean)
Precision:
- API returns distance in meters
- Node converts to kilometers automatically
- Result: floating-point number with decimal places
Common Errors and Solutions
Error: "ErrInvalidArg: Coordinate 1/2 cannot be empty"
Cause: Missing coordinate input.
Solution:
- Verify both coordinate variables have values
- Check for null/undefined values
- Use conditional logic to skip empty coordinates
Error: "ErrInvalidArg: Coordinate 1/2 format error"
Cause: Coordinate string format is incorrect.
Solution:
- Ensure format: "latitude,longitude"
- Check for missing comma:
"40.7128-74.0060"❌ - Verify two parts:
"40.7128,"❌ - Remove extra commas:
"40.7128,-74.0060,0"❌
Error: "ErrInvalidArg: Coordinate 1/2 parse error"
Cause: Latitude or longitude values are not valid numbers.
Solution:
- Verify numeric values:
"forty,seventy"❌ - Check for typos:
"40.7128,-74.OO6O"(letter O instead of zero) ❌ - Ensure no special characters:
"(40.7128,-74.0060)"❌
Error: "ErrCredentials: No Credential Content"
Cause: Google Maps API key is missing or invalid.
Solution:
- Create credential in Robomotion vault
- Add your Google Maps API key to the credential
- Select the credential in node's Options
- Verify credential field name is "value"
Error: "ErrGoogleMaps: No route found"
Cause: Google Maps cannot find a driving route between the coordinates.
Solution:
- Verify both coordinates are on land and accessible by road
- Check if locations are on different continents/islands
- Confirm coordinates are not in ocean or restricted areas
- For islands, ferry routes are not included
- Try reverse direction (sometimes one-way restrictions apply)
Error: "ErrGoogleMaps: OVER_QUERY_LIMIT"
Cause: Exceeded API quota or rate limits.
Solution:
- Check quota in Google Cloud Console
- Add delays: Use "Delay After" property (0.5-1 second)
- Implement caching to reduce duplicate requests
- Upgrade billing plan if needed
- Batch process during off-peak hours
Error: "ErrGoogleMaps: REQUEST_DENIED"
Cause: API key lacks Directions API permissions.
Solution:
- Enable Directions API in Google Cloud Console
- Verify API key restrictions allow the request
- Check billing is enabled on Google Cloud account
- Ensure API key has no IP/referrer restrictions blocking the request
Error: "ErrGoogleMaps: INVALID_REQUEST"
Cause: Malformed request or coordinates out of range.
Solution:
- Verify latitude: -90 to 90
- Verify longitude: -180 to 180
- Check coordinate order: latitude first, longitude second
- Ensure decimal format, not DMS (degrees/minutes/seconds)
Distance Seems Wrong or Too Short/Long
Issue: Unexpected distance value.
Possible causes and solutions:
-
Coordinates Swapped
- Check: latitude first, longitude second
- Fix:
"40.7128,-74.0060"not"-74.0060,40.7128"
-
Route Takes Detour
- Directions API finds legal driving route
- May avoid highways, one-way streets
- Result may be longer than expected
-
Same Start and End
- Distance will be very small or zero
- Verify coordinates are different
-
Wrong Coordinate Precision
- Too few decimal places = imprecise location
- Use at least 4-6 decimal places
Usage Notes
- Coordinates should be provided in decimal degrees format
- The distance represents actual driving distance (not straight-line)
- The result is returned in kilometers
- For coordinate formatting, use comma separator: "latitude,longitude"
- This calculation requires an internet connection to access Google Maps API
- The API key must have Directions API permissions enabled
- If no route is found between coordinates, an error will be returned
- The node accounts for one-way streets, road closures, and traffic restrictions
- Uses default driving mode (car) - does not support walking, cycling, or transit
- Returns distance for the primary recommended route
- Does NOT account for real-time traffic (uses base road network)
- Ferry routes and toll preferences are not customizable
- Distance is the sum of all route legs in the journey