Use the Routes API (preferred over the legacy Directions API): POST to https://routes.googleapis.com/directions/v2:computeRoutes with origin, destination, and intermediates[] for waypoints; set X-Goog-FieldMask to routes.duration,routes.distanceMeters,routes.legs.
For ordered multi-stop routes, set optimizeWaypointOrder: false and list intermediates in the desired order; set it to true to let Google optimize the waypoint order (TSP optimization), then read back the optimizedIntermediateWaypointIndex array to know the computed order.
Specify travelMode: DRIVE, WALK, BICYCLE, or TRANSIT; for transit, add transitPreferences with allowedTravelModes and routingPreference.
Set departureTime (RFC 3339 UTC) or arrivalTime for traffic-aware routing; omitting both returns duration without real-time traffic, which underestimates travel time in congested cities.
Parse the response: routes[0].legs[] maps to each segment between stops; each leg has duration (seconds), distanceMeters, and steps[] with navigation instructions; sum leg durations for total trip time.
For itinerary planning across days, batch waypoints into per-day sub-routes — the API supports up to 25 waypoints per request on standard plans, but large batches increase latency and cost.
Known gotchas
The Routes API bills per request and per feature (basic vs advanced, traffic vs no-traffic); always set a precise X-Goog-FieldMask to avoid being billed for Advanced features you did not intend to use.
Driving duration estimates assume normal traffic for the given departure time — they are not guarantees; for airport transfers in booking confirmations, add a substantial buffer (30–60 min) and advise users accordingly.
TRANSIT mode results depend on the availability of transit data for the region — many cities outside major markets have incomplete or absent transit schedules, causing fallback to WALK or empty results without a clear error.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp