# 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.

Source: https://www.wayline.cloud/docs/guides/mileage-for-check-ins

Field reps, technicians and drivers record check-ins throughout the day. The [Batch Distance API](/products/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

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

## 3. Store the result with an audit trail

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](/docs/api/compute-distance-batch) · [Sales territory mileage](/use-cases/sales-territory-mileage)
