latlng

Fleet management and vehicle tracking

Keep every vehicle's live position and status in one place, answer dispatch questions in milliseconds, and let latlng tell your systems when vehicles arrive at or leave a depot, customer site, or service area.

The challenge

Fleet software has to answer the same questions thousands of times a minute: where is each vehicle, which ones are available, what's closest to this job, and who just left the depot? Relational databases can answer them, but constant position updates create write load and index churn, and nothing tells you when a vehicle crosses a boundary unless you poll and diff.

Most teams end up with a pipeline of cron jobs, caches, and custom geometry code that is hard to keep correct — especially around restarts and failed notifications.

How latlng helps

Fleets as collections

Create one collection per fleet, region, or customer (fleet-hamburg, fleet-berlin). Queries, geofences, and access tokens all work per collection or name pattern.

Vehicles with live status

Each vehicle is an object with a position and fields such as status, speed, type, or capacity. Position reports keep existing fields, and status changes don't need to resend the position.

Nearest available vehicle

nearby returns vehicles sorted by distance and filtered by fields — for example, only available vans within 5 km — with the distance on each result.

Depot and site geofences

Register depots, customer sites, and service areas as polygon or radius geofences. latlng emits enter, exit, inside, outside, and cross events as vehicles move.

Reliable notifications

Geofence events are delivered as webhooks from a durable queue with exponential backoff and dead-lettering, so a brief outage in your backend doesn't lose arrivals.

Offline detection

Send expire_seconds with every position report. When a tracker goes silent, the vehicle expires: it drops out of queries and fires a Del event to hooks that listen for it.

How it fits together

  1. 01

    Trackers report

    Telematics units or driver apps send positions and status to your ingestion service, which writes them to latlng.

  2. 02

    latlng indexes

    Positions update the in-memory spatial index; every write is checked against the fleet's geofences.

  3. 03

    Events go out

    Enter and exit events are delivered to webhooks and live WebSocket channels.

  4. 04

    Apps query

    Dispatch, customer ETA pages, and dashboards query nearby and within to show the current state.

Find the nearest available vehicle

One request returns the five closest available vehicles within 5 km, sorted by distance.

HTTP
curl -s -X POST http://127.0.0.1:7421/collections/fleet-hamburg/search/nearby \
  -H 'content-type: application/json' \
  -d '{
    "lat": 53.5511, "lon": 9.9937, "meters": 5000,
    "options": {
      "limit": 5,
      "where_in_filters": [ { "field": "status", "values": ["available"] } ]
    }
  }'

Where latlng stops

  • latlng stores the current position of each vehicle, not its history. Forward position reports or webhook events to a time-series database or PostGIS for trip history and reporting.
  • It doesn't do routing, ETAs, or road-network distances. nearby uses straight-line distance — combine it with a routing engine when drive time matters.
  • Geofence webhooks are HTTP only. To feed Kafka, NATS, or a queue, point the hook at a small relay service.

Frequently asked questions

How many vehicles can latlng track?

latlng keeps objects in memory with an R-tree index, so capacity depends mainly on available RAM and update rate. It includes a benchmark harness so you can measure throughput for your own fleet size and geofence count.

Should each fleet be its own collection?

Usually, yes. Queries and geofences run per collection, and JWT permissions are scoped by collection name patterns, so one collection per fleet, region, or customer keeps queries fast and access control simple.

How do I detect vehicles that stopped reporting?

Send expire_seconds with each position update. Because every update resets the TTL, it works as a heartbeat: if no update arrives in time, the vehicle is deleted by the background expiry sweep, disappears from queries, and fires a Del event to hooks whose commands include Del — so you can alert on it.

Can I keep a history of vehicle positions?

latlng keeps the latest state per vehicle. For history, write the same position stream, or latlng's geofence events, into a database built for it, such as PostgreSQL with PostGIS or a time-series store.