Route optimization API: plan a multi-stop day by real drive time

How a route optimization API orders 5 to 100 stops by real drive time, when it beats manual planning, how to call it and what it costs per stop.

By Wayline Engineering · · Updated · 3 min read

A route optimization API takes a start point and a list of stops and returns the order to visit them that minimizes total drive time, along with the distance and time of each leg. It is the "traveling salesman" problem solved on a real road network, behind one HTTPS call. This post explains how it works, when it pays off, and how to call it.

Why ordering stops by hand goes wrong

People plan routes by looking at a map and connecting nearby pins. On a road network that intuition fails in predictable ways:

  • Rivers and rail lines. Two stops 800 meters apart on a map can be 6 km apart by road if the nearest bridge is upstream.
  • One-way streets and divided highways. The "next" stop across the road may need a U-turn several minutes away.
  • Speed differences. A longer detour on a highway is often faster than a short hop through a congested center.

A drive-time matrix captures all of this, and an optimizer searches orders against it. On a typical day of 10 to 20 stops the saved time is often substantial, and it compounds across every rep, technician or rider on your team. Measure it on your own data: compare yesterday's actual order with the optimized order for the same stops.

How the Wayline Route Optimization API works

  1. Every stop is snapped to the nearest road in its region (the response reports how far each one moved).
  2. A full drive-time matrix between the stops is computed on the road graph (car or motorcycle profile).
  3. A solver searches for the order with the lowest total drive time, given your start and end rules.
  4. You get order (input indices in visiting order), per-leg distance_meters and duration_seconds with readable text, and totals.

Calling it

bash
curl -X POST "https://api.wayline.cloud/v1/optimize" \
  -H "Authorization: Bearer $WAYLINE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "end": "start",
    "stops": [
      {"lat": 23.7925, "lng": 90.4078},
      {"lat": 23.7330, "lng": 90.4172},
      {"lat": 23.7639, "lng": 90.3889},
      {"lat": 23.7465, "lng": 90.3760},
      {"lat": 23.7937, "lng": 90.4066}
    ]
  }'
  • stops[0] is the start (home or depot) by default. Use "start": "any" to let the solver pick.
  • end: "any" (finish at the best stop), "last" (finish at the last stop you gave) or "start" (come back).
  • profile: "car" (default) or "motorcycle" where the region offers it.
  • Up to 100 stops per request, all in one region.

What it costs

One optimize unit per stop on a successful response, so a 15-stop plan is 15 units. Errors are never billed and new accounts get free units. See the pricing page for the current per-unit price.

When to use something else

NeedUse
One vehicle, 2 to 100 stops, fastest orderRoute Optimization API
Many vehicles, time windows, capacitiesDistance Matrix API + a solver such as VROOM or OR-Tools
Just distance and time for stops already in orderBatch Distance API
Turn-by-turn directions for the chosen orderRouting API with waypoints

Practical tips

  • Plan once, then re-plan on change. Optimize in the morning; call again only when stops are added or cancelled.
  • Watch POINT_FAR_FROM_ROAD warnings. A stop geocoded to the wrong place will distort the whole plan.
  • Add a buffer for peak hours. Drive times do not include live traffic.
  • Record actual arrival times. Comparing plan and reality is the fastest way to find bad addresses and tune buffers.

The field sales guide shows the complete flow: plan the day, label check-ins with addresses, and compute end-of-day mileage.

GuidesRoutingField service

Start building in minutes

Create an account, grab a test key and make your first request in under five minutes.