latlng
Live demo · running locally in your browser

A geospatial object engine for moving things.

latlng is an open-source spatial database in Rust. Index moving points, define geofences as code, stream geofence events as they happen — natively, or directly in the browser via WebAssembly.

Features

Built for things that move.

Core commands and queries are available over HTTP/JSON and Cap'n Proto, geofence events stream over WebSocket subscriptions, and the browser SDK runs the same Rust core in WebAssembly.

Spatial indexing

R-tree spatial indexing and field indexes for nearby, within, intersects, scan, and text search — backed by a portable Rust core.

Geofencing as code

Define hooks with circles, bounds, GeoJSON areas, or roaming distance. Emit inside, outside, enter, exit, cross, and roam events as objects move.

Webhook eventing

Durable HTTP POST delivery from a SQLite-backed outbox. Per-request timeouts, exponential backoff, dead-letter — at-least-once with stable event IDs.

Three transports

HTTP/JSON with generated OpenAPI, WebSocket subscriptions, and async Cap'n Proto RPC — all backed by the same engine and auth model.

Pluggable storage

Run the server in memory or on an append-only file. The Rust storage layer also includes SQLite for embedded use, plus AOF compaction, verification, backup, and restore.

Single-leader replication

Streaming replication over Cap'n Proto with checksum-based resume. Read-only followers catch up incrementally and serve queries after initial sync.

Auth that fits

Static bearer tokens, HMAC JWTs, asymmetric JWTs from PEM keys or JWKS. Claims-based authz scoped per collection.

Browser-native

The same engine compiles to wasm and runs in a Web Worker. Build local-first map apps with no server in the loop — like the demo above.

Operational from day one

Prometheus metrics, structured logging, HTTP rate limits per principal, runtime config rewrite — built for production, not just demos.

How it works

One engine. Two shapes.

latlng compiles a single Rust core into the form that fits where you run it — a service you deploy or a worker that ships with your web app.

Native server

latlng-server

Run it as a standalone process. HTTP/JSON, WebSocket subscriptions, and async Cap'n Proto RPC, all from the same binary, behind the same auth.

# Start the server binary
latlng-server

# Store a point
curl -sS -X POST http://127.0.0.1:7421/collections/fleet/objects/truck-1 \
  -H 'content-type: application/json' \
  -d '{"object":{"Point":{"lat":53.55,"lon":9.99,"z":null}}}'

# Query nearby points
curl -sS -X POST http://127.0.0.1:7421/collections/fleet/search/nearby \
  -H 'content-type: application/json' \
  -d '{"lat":53.55,"lon":9.99,"meters":1000,"options":{}}'
Browser

@latlng/wasm

The same engine, compiled to WebAssembly and pinned inside a Web Worker. Local-first geospatial — no server, no network, no key.

import { createLatLng } from "@latlng/wasm";

const db = await createLatLng();
await db.createCollection("fleet");
await db.setPoint("fleet", "truck-1", { lat: 53.55, lon: 9.99 });

const nearby = await db.nearby("fleet", {
  lat: 53.55,
  lon: 9.99,
  meters: 1000,
});

console.log(nearby.results);
Getting started

Run latlng where you need it.

Use a release binary, pull the published container, or build the native server and CLI from source.

Release binaries

Download from GitHub

Release archives contain the native server and CLI. Pick the asset for your platform, extract it, and start the server binary.

Assets are named linux-x64, macos-arm64, and windows-x64.

curl -fsSL -o latlng-linux-x64.tar.gz \
  "https://github.com/tobilg/latlng/releases/latest/download/latlng-linux-x64.tar.gz"

tar -xzf latlng-linux-x64.tar.gz
chmod +x latlng-server latlng-cli
./latlng-server
Docker

Run the image

The published image runs as a non-root user and expects a mounted config file at /etc/latlng/latlng.toml.

The example config exposes HTTP, WebSocket, metrics, and Cap'n Proto ports.

TAG=v0.1.1
git clone https://github.com/tobilg/latlng.git
cd latlng

docker run --rm --name latlng \
  -p 7421:7421 -p 7422:7422 \
  -v "$(pwd)/examples/docker/single-node.toml:/etc/latlng/latlng.toml:ro" \
  -v latlng-data:/var/lib/latlng \
  tobilg/latlng:$TAG
From source

Build locally

Build the release binaries yourself with Cargo. The workspace uses Rust 1.94 and the Cap'n Proto compiler.

The release build produces target/release/latlng-server and target/release/latlng-cli.

git clone https://github.com/tobilg/latlng.git
cd latlng

cargo build --release -p latlng-server -p latlng-cli
./target/release/latlng-server

Run it on a server. Or in a tab.

latlng is MIT-licensed and ready to clone today. Native server, browser SDK, single-leader replication — all in the same repository.