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.
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
[
{ "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.
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 days2. 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"}'const res = await fetch("https://api.wayline.cloud/v1/distance/batch", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.WAYLINE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"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"
}),
});
if (!res.ok) throw new Error(`Wayline ${res.status}: ${await res.text()}`);
console.log(await res.json());import os, requests
res = requests.post(
"https://api.wayline.cloud/v1/distance/batch",
json={
"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"
},
headers={"Authorization": f"Bearer {os.environ['WAYLINE_API_KEY']}"},
timeout=10,
)
res.raise_for_status()
print(res.json())package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
)
func main() {
body := `{"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"}`
req, _ := http.NewRequest("POST", "https://api.wayline.cloud/v1/distance/batch", strings.NewReader(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("WAYLINE_API_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
out, _ := io.ReadAll(res.Body)
fmt.Println(res.Status, string(out))
}<?php
$ch = curl_init("https://api.wayline.cloud/v1/distance/batch");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("WAYLINE_API_KEY"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => '{"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"}',
CURLOPT_TIMEOUT => 10,
]);
print_r(json_decode(curl_exec($ch), true));require "net/http"
require "json"
uri = URI("https://api.wayline.cloud/v1/distance/batch")
req = Net::HTTP::Post.new(uri, "Content-Type" => "application/json")
req["Authorization"] = "Bearer #{ENV.fetch("WAYLINE_API_KEY")}"
req.body = {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"}.to_json
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(req) }
puts JSON.parse(res.body)import java.net.URI;
import java.net.http.*;
public class Main {
public static void main(String[] args) throws Exception {
String body = """
{
"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"
}
""";
var req = HttpRequest.newBuilder(URI.create("https://api.wayline.cloud/v1/distance/batch"))
.header("Authorization", "Bearer " + System.getenv("WAYLINE_API_KEY"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body)).build();
var res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(res.statusCode() + " " + res.body());
}
}import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
Future<void> main() async {
final res = await http.post(
Uri.parse('https://api.wayline.cloud/v1/distance/batch'),
headers: {
'Authorization': 'Bearer ${Platform.environment['WAYLINE_API_KEY']}',
'Content-Type': 'application/json',
},
body: jsonEncode({
"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"
}),
);
print(jsonDecode(res.body));
}A day with N check-ins costs N − 1 units.
3. Store the result with an audit trail
{
"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