How to calculate mileage reimbursement for field teams with an API
Turn field check-ins into audited, road-based mileage logs with one API call per rep per day — grouping by local time zone, edge cases and cost.
By Wayline Engineering · · Updated · 2 min read
Most field teams reimburse mileage from self-reported numbers or straight-line estimates. Both are wrong in predictable ways: self-reporting drifts, and straight lines under-count real driving. The fix is to compute mileage from the check-ins your CRM already records, using road distance between consecutive stops — one API call per employee per day.
Why straight-line mileage under-reimburses
A rep driving across a city rarely follows a straight line. Rivers, highways and one-way streets add distance. In our experience routing urban trips, road distance commonly runs well above the straight-line figure; the exact ratio depends on the street network, which is exactly why you should measure it rather than apply a fixed multiplier. Our free distance calculator shows both numbers side by side.
The pattern: one batch per rep per local day
- Export check-ins with
user_id, timestamp (UTC) and coordinates. - Group by user and local calendar day in the user's time zone — an evening visit in Los Angeles is still "today" even though it is tomorrow in UTC.
- Send each group, in time order, to the Batch Distance API. N check-ins produce N − 1 legs and cost N − 1 units.
- Store the per-leg results with
request_idandmap_versionfor audits.
from collections import defaultdict
from datetime import datetime
from zoneinfo import ZoneInfo
from wayline import Wayline
client = Wayline() # reads WAYLINE_API_KEY
def daily_mileage(checkins, tz_for_user):
days = defaultdict(list)
for c in sorted(checkins, key=lambda c: c["at"]):
tz = ZoneInfo(tz_for_user[c["user_id"]])
day = datetime.fromisoformat(c["at"]).astimezone(tz).date()
days[(c["user_id"], day)].append((c["lat"], c["lng"]))
for (user, day), points in days.items():
if len(points) < 2:
continue
r = client.distance_batch(points=points, units="imperial")
yield user, day, r.total_distance_miles, r.request_id, r.map_versionEdge cases worth handling
| Situation | What to do |
|---|---|
| Two check-ins at the same place | De-duplicate consecutive points within ~50 m before calling the API. |
A leg returns NO_ROUTE | Exclude it and flag for review (often a ferry or a bad GPS fix). |
| Home → first visit | Decide policy: many companies exclude the commute; include or drop the first leg accordingly. |
| Very long days | Split into chunks that share the boundary point to stay within your plan's batch limit. |
What it costs
At one unit per leg, a rep with 8 visits a day generates 7 units per day. Multiply by reps and working days and apply the per-unit price on our pricing page — the calculator there does this for you.
The rate is a policy decision
Wayline computes distances. Your reimbursement rate — often the current IRS standard mileage rate for US companies — and tax treatment are decisions for your finance team or advisor.
Draft for review: confirm the urban detour claim with our own measured sample before publishing, and add a diagram of the grouping flow.