Prompt
How do I estimate ETAs for last-mile deliveries using a maps API?
Latest observation
To estimate ETAs for last-mile deliveries with a maps API, the usual approach is:
1) Get route travel time from the maps API
Most maps/routing APIs provide:
- Distance
- Driving time
- Traffic-adjusted ETA if supported
Typical flow:
- Take the delivery stop’s latitude/longitude.
- Call a routing/directions API from the driver’s current location or last stop.
- Use the returned travel time as the base ETA.
Common APIs:
- Google Maps Routes/Directions API
- Mapbox Directions API
- HERE Routing API
- Bing Maps
- OSRM / OpenRouteService
2) Use the right origin
For last-mile deliveries, the ETA should usually be based on:
- Driver’s current GPS location, not just warehouse location
- Or previous stop if you’re sequencing multiple drops
If you’re doing multi-stop routes, calculate ETAs sequentially:
- ETA(stop 1) = now + travel time from current position
- ETA(stop 2) = ETA(stop 1) + service time at stop 1 + travel time to stop 2
- and so on
3) Add stop/service time
Maps APIs usually estimate only travel time, not time spent:
- parking
- walking to the door
- handoff/signature
- apartment access delays
So add a service buffer per stop, for example:
- Residential house: 2–5 min
- Apartment/commercial: 5–10+ min
4) Account for traffic and time of day
If your API supports it, request:
- departure_time=now
- traffic_model or equivalent
- historical traffic or live traffic
This makes ETAs much more realistic, especially in cities.
5) Recompute dynamically
Last-mile ETAs drift as conditions change. Recalculate:
- when the driver moves significantly
- after each completed stop
- every few minutes during active delivery
- when route deviation is detected
6) Improve accuracy with correction factors
Raw map ETAs are often optimistic. You can calibrate them using your own historical data:
- Compare predicted ETA vs actual arrival time
- Learn correction factors by:
- city/zone
- time of day
- weekday/weekend
- vehicle type
- stop type
- traffic level
A simple version:
ETA = maps_travel_time * factor + service_time- Example factor: 1.10–1.30 depending on your network
7) Handle multi-stop optimization separately
If you need route ordering as well as ETAs:
- Use a route optimization API or solve a VRP/TSP problem
- Then pass the ordered stops to the routing API for travel-time ETAs
8) Basic ETA formula
A practical starting point:
ETA_next_stop = current_time
+ maps_travel_time(origin, destination, traffic=true)
+ service_time_estimate
+ buffer
For a route of multiple stops:
ETA_stop[i] = ETA_stop[i-1]
+ service_time_stop[i-1]
+ maps_travel_time(stop[i-1], stop[i])
9) Example implementation idea
Pseudo-code:
origin = driver_location
eta = now
for stop in delivery_stops:
travel = maps_api.get_travel_time(origin, stop.location, traffic=True)
service = estimate_service_time(stop)
eta = eta + travel + service
stop.eta = eta
origin = stop.location
10) Watch out for common pitfalls
- Using warehouse departure time instead of live driver location
- Ignoring traffic
- Ignoring service time
- Not recalculating after delays
- Assuming map ETA = delivery ETA
- Not smoothing noisy GPS updates
If you want, I can also show:
- a Google Maps API example
- a Mapbox/HERE example
- or a full ETA model for multi-stop delivery routing.