Documentation menu

Guides

Delivery radius by drive time

Build a delivery-radius checker in 15 minutes — decide which stores can deliver to an address within a drive-time limit using the distance matrix API.

Updated Dec 1, 2026 View Markdown

A 5-mile circle around a store ignores rivers, bridges and highways. A drive-time radius reflects how far a driver can actually get. This guide builds a checker that answers: which of my stores can reach this customer in under 20 minutes?

1. One request per checkout

Send the customer as the only destination and your candidate stores as origins. A 1 × N or N × 1 matrix costs N units.

curl -X POST "https://api.wayline.cloud/v1/matrix" \
  -H "Authorization: Bearer $WAYLINE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"origins":[{"lat":37.788,"lng":-122.4075},{"lat":37.8313,"lng":-122.2852}],"destinations":[{"lat":37.8044,"lng":-122.2712},{"lat":37.8716,"lng":-122.2727},{"lat":37.9358,"lng":-122.3478}],"units":"imperial"}'

2. Filter by threshold

typescript
type Store = { id: string; lat: number; lng: number };

export async function storesWithin(customer: { lat: number; lng: number }, stores: Store[], maxMinutes = 20) {
  const res = await fetch("https://api.wayline.cloud/v1/matrix", {
    method: "POST",
    headers: { Authorization: `Bearer ${process.env.WAYLINE_API_KEY}`, "Content-Type": "application/json" },
    body: JSON.stringify({ origins: stores.map(({ lat, lng }) => ({ lat, lng })), destinations: [customer], metrics: "duration" }),
  });
  if (!res.ok) throw new Error(`Wayline ${res.status}`);
  const data = await res.json();
  return stores
    .map((s, i) => ({ store: s, seconds: data.rows[i].elements[0].duration_seconds as number | undefined, status: data.rows[i].elements[0].status }))
    .filter((x) => x.status === "OK" && x.seconds! <= maxMinutes * 60)
    .sort((a, b) => a.seconds! - b.seconds!);
}

3. Pre-filter to save units

Only send stores that could plausibly qualify. A cheap straight-line pre-filter (e.g. within 2× your drive-time radius at highway speed) removes far stores before the matrix call.

4. Cache answers

Customer addresses repeat. Cache (store, rounded customer coordinate) → seconds keyed with the region map_version. See Caching.

Caveats

Drive times are free-flow (no live traffic). Leave a safety margin, or scale by a time-of-day factor you measure from real deliveries.

Related: Last-mile delivery · Matrix reference