Prompt
How do I add route planning and ETAs to a delivery app?
Latest observation
To add route planning and ETAs to a delivery app, you typically need three pieces:
- Geocoding: convert addresses to coordinates
- Routing/optimization: determine the best delivery order and route
- ETA prediction: estimate arrival times based on distance, traffic, and stop times
Here’s a practical approach.
1) Collect the right data
For each delivery stop, store:
- Pickup location and drop-off location
- Latitude/longitude for each stop
- Delivery time window, if any
- Service duration at the stop
- Driver start location
- Vehicle constraints, if relevant
You’ll usually want a schema like:
ordersstopsdriversroutesroute_stops
2) Geocode addresses
Before routing, turn addresses into coordinates.
Use:
- Google Geocoding API
- Mapbox Geocoding
- HERE Geocoding
- OpenStreetMap/Nominatim
Store the resulting lat/lng so you don’t geocode the same address repeatedly.
3) Plan routes
There are two common problems:
A. Single route navigation
If a driver already has a set of stops, you just need directions between them.
Use a directions API:
- Google Directions API
- Mapbox Directions
- HERE Routing
- OSRM / GraphHopper if self-hosting
This gives:
- turn-by-turn path
- distance
- duration
- traffic-aware duration, if supported
B. Multi-stop route optimization
If you need to determine the best order of stops, use a route optimization solver.
This is the Vehicle Routing Problem (VRP) or Traveling Salesman Problem (TSP), depending on complexity.
Options:
- Google Route Optimization API
- Mapbox Optimization API
- OR-Tools
- Routific, OptimoRoute, Onfleet integrations
You can optimize for:
- shortest total distance
- earliest completion time
- time windows
- vehicle capacity
- driver shifts
- pickup and delivery pairing
If you want full control, Google OR-Tools is a strong choice.
4) Compute ETAs
For ETAs, combine:
- travel time from routing API
- expected service time at each stop
- traffic adjustments
- historical delay patterns
A simple ETA calculation:
ETA(stop N) =
current time
+ travel time to stop 1
+ service time stop 1
+ travel time to stop 2
+ service time stop 2
...
+ travel time to stop N
If using live traffic, recalculate every time the route changes or every few minutes.
5) Update ETAs dynamically
Delivery ETAs should change as the driver progresses.
Update when:
- driver starts route
- driver completes a stop
- driver is delayed
- traffic conditions change
- a stop is added/removed
You can recalculate in the backend and push updates to the app via:
- WebSockets
- Server-sent events
- Push notifications
- periodic polling
6) Show route and ETA in the app
Typical UI:
- map with current route
- ordered stop list
- ETA for each stop
- “next stop” indicator
- live driver location
- delay notifications
Useful details to display:
- estimated arrival time
- remaining stops
- remaining distance/time
- confidence range, e.g. “ETA 2:10–2:25 PM”
7) Suggested architecture
Backend
- Ingest orders
- Geocode addresses
- Build/optimize routes
- Store route plans and ETAs
- Recompute on events
Mobile app
- Show map
- Show route summary and stop list
- Share driver location
- Refresh ETAs
External services
- Maps/geocoding provider
- Traffic-aware directions
- Optimization engine
8) Example flow
- Dispatcher assigns 12 orders to a driver
- System geocodes all stops
- Optimization service orders stops efficiently
- Routing API computes distance/duration between each stop
- Backend calculates ETAs
- Driver app shows the route
- As the driver progresses, the backend updates ETAs in real time
9) If you want a fast MVP
Use managed APIs:
- Google Maps Platform for geocoding + directions
- Google Route Optimization API or OR-Tools for multi-stop routing
- WebSocket updates for live ETAs
This is the quickest path to production.
10) If you want to self-host
Use:
- Nominatim for geocoding
- OSRM or GraphHopper for routing
- OR-Tools for optimization
This reduces vendor costs but takes more infrastructure work.
11) Important edge cases
Handle:
- traffic spikes
- failed geocoding
- missed stops
- re-routing mid-shift
- pickups and deliveries with precedence constraints
- time windows
- driver breaks
- vehicle capacity
- road closures
12) Recommended implementation plan
Phase 1
- geocode addresses
- show a map
- compute ETA from routing API
Phase 2
- add multi-stop optimization
- update ETAs dynamically
- support stop sequencing
Phase 3
- add traffic-aware predictions
- historical delay modeling
- automatic re-optimization
- dispatcher controls
If you want, I can also give you:
- a sample database schema,
- a backend API design, or
- a code example using Google Maps + OR-Tools.