Documentation menu

Guides

Mileage for consecutive check-ins

Turn a day of field check-ins into an audited mileage log with the batch distance endpoint, grouping by each employee's local day and time zone.

Updated Dec 1, 2026 View Markdown

Field reps, technicians and drivers record check-ins throughout the day. The Batch Distance API turns each day's ordered check-ins into per-leg road distances and totals in one request.

The data model

json
[
  { "user_id": "u_42", "at": "2026-11-20T13:05:00Z", "lat": 23.7925,  "lng": 90.4078 },
  { "user_id": "u_42", "at": "2026-11-20T15:40:00Z", "lat": 23.7937, "lng": 90.4066 },
  { "user_id": "u_42", "at": "2026-11-20T19:15:00Z", "lat": 23.7465, "lng": 90.376 }
]

1. Group by user and local day

"Today" depends on where the employee works. Group timestamps by the user's IANA time zone, not UTC — otherwise an evening visit on the West Coast lands on the next day.

python
from collections import defaultdict
from datetime import datetime
from zoneinfo import ZoneInfo

def group_by_local_day(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"]])  # e.g. "America/New_York"
        local_day = datetime.fromisoformat(c["at"].replace("Z", "+00:00")).astimezone(tz).date()
        days[(c["user_id"], local_day)].append({"lat": c["lat"], "lng": c["lng"]})
    return days

2. Send each day as one batch

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

A day with N check-ins costs N − 1 units.

3. Store the result with an audit trail

Response (example)
{
  "request_id": "req_01JD8Q6C9T4P",
  "legs": [
    {
      "from_index": 0,
      "to_index": 1,
      "distance_meters": 6120,
      "duration_seconds": 840,
      "status": "OK"
    },
    {
      "from_index": 1,
      "to_index": 2,
      "distance_meters": 3010,
      "duration_seconds": 420,
      "status": "OK"
    },
    {
      "from_index": 2,
      "to_index": 3,
      "distance_meters": 12840,
      "duration_seconds": 1080,
      "status": "OK"
    }
  ],
  "total_distance_meters": 21970,
  "total_duration_seconds": 2340,
  "region": "us",
  "map_version": "20261121-2330",
  "units_charged": 3
}

Store each leg with request_id, region and map_version. If someone disputes a reimbursement later, you can show exactly which data produced the number.

4. Apply your reimbursement rate

Multiply total miles (total_distance_meters / 1609.344) by your policy rate — for US companies often the current IRS standard mileage rate. Wayline computes distances; reimbursement policy and tax treatment are decisions for your finance team.

Edge cases

  • Legs with status: "NO_ROUTE" (e.g. a check-in on an island): exclude them and flag for review.
  • Duplicate check-ins at the same place: a zero-length leg costs one unit; de-duplicate consecutive points within ~50 m first to save units.
  • Large days: batches are limited by your plan's maximum points; split into consecutive chunks that share the boundary point.

Related: Batch endpoint reference · Sales territory mileage