latlng

Delivery zones and arrival notifications

Decide instantly which zone, depot, or pricing area an address belongs to, and notify customers and dispatchers the moment a driver arrives at a stop or leaves the hub.

The challenge

Last-mile delivery runs on geography. Checkout needs to know whether an address is serviceable and which zone's fee applies. Dispatch wants to know when a driver leaves the hub and reaches each stop. Customers expect an "arriving now" message at the right moment — not five minutes late because a job only polls every few minutes.

Zones change often, notifications must not get lost, and the same events usually need to reach several systems.

How latlng helps

Zones as data

Store delivery zones as GeoJSON polygons in their own collection, with fields such as fee or depot. Update a zone by writing the object again — no deploy needed.

Point-in-zone lookups

intersects with a GeoJSON point returns the zones that contain an address, including their fields, in a single request.

Arrival and departure events

Register each hub or customer site as a geofence hook. latlng sends an enter event when a driver arrives and an exit event when they leave.

Only the vehicles that matter

Geofence queries accept field filters, so a stop's fence can ignore vehicles that are parked or on another route.

No lost notifications

Webhook jobs are written to the durable log with the position update, retried with exponential backoff, and dead-lettered instead of dropped.

Deduplication built in

Every delivery carries stable X-LatLng-Event-Id and X-LatLng-Job-Id headers, so your notification service can safely ignore repeats.

How it fits together

  1. 01

    Checkout asks

    Your shop calls latlng with the geocoded address to find the zone and its delivery fee.

  2. 02

    Drivers report

    Driver apps send positions with the current route and status as fields.

  3. 03

    Fences fire

    Hub and stop geofences emit exit and enter events as drivers move.

  4. 04

    Customers hear

    Your notification service turns webhooks into SMS, push, or email — once per event.

Which zone contains this address?

Store zones as polygons, then look up a geocoded address with a single intersects query.

HTTP
# Store a zone with its delivery fee
curl -s -X POST http://127.0.0.1:7421/collections/zones/objects/zone-mitte \
  -H 'content-type: application/json' \
  -d '{
    "object": { "GeoJson": { "type": "Polygon", "coordinates": [[
      [9.96, 53.54], [10.03, 53.54], [10.03, 53.57], [9.96, 53.57], [9.96, 53.54]
    ]] } },
    "fields": [ { "name": "fee", "value": { "type": "number", "value": 1.5 } } ]
  }'

# Look up a geocoded address
curl -s -X POST http://127.0.0.1:7421/collections/zones/search/intersects \
  -H 'content-type: application/json' \
  -d '{ "area": { "GeoJson": { "type": "Point", "coordinates": [9.9937, 53.5511] } },
        "options": { "output": "Ids" } }'
# {"count":1,"cursor":0,"results":[{"id":"zone-mitte","fields":{"values":{"fee":{"type":"number","value":1.5}}}, ...}]}

Where latlng stops

  • latlng works with coordinates. Geocode addresses with a geocoding service before querying.
  • It doesn't plan routes, sequence stops, or compute ETAs. Use a routing or optimization engine for that and latlng for the live position and arrival events.
  • Geofence hooks take their area inline. When you change a zone polygon that is also used as a fence, update the hook definition too.

Frequently asked questions

How do I check whether an address is in my delivery area?

Store your delivery zones as GeoJSON polygons in a collection, geocode the address, and run an intersects query with a GeoJSON point. The response lists every zone that contains the point, along with fields such as the delivery fee.

How are customers notified when a driver arrives?

Register the stop as a geofence hook that detects enter events. When the driver's position update crosses the boundary, latlng sends a webhook to your notification service, which messages the customer.

What happens if my notification service is down?

Webhook jobs stay in latlng's durable queue and are retried with exponential backoff. After the configured retry budget they move to a dead-letter state, which you can monitor through the admin endpoint and Prometheus metrics.

Can one stop notify several systems?

Yes. Register several hooks with the same geofence and different endpoints, or have one receiver fan events out to the systems that need them.