• Start

Geospatial

Distance and proximity

Measure distance between points, reason about buffers and proximity, and use geohash helpers for hierarchical location keys alongside SurrealDB geo functions.

Many applications need more than boolean inside/outside tests: they need how far apart two geometries are, whether entities fall within a buffer around a route, or a compact geohash key for bucketing nearby points.

The shortest path between two points on the Earth is often approximated in databases using great-circle or similar metrics, depending on your CRS and functions available. SurrealDB’s geo::distance() calculates the distance between two geolocation points, and can be useful when ranking “nearest” results or filtering by a maximum radius.

When you only need ordering, you may still use distance in an ORDER BY clause. When you need a hard cutoff, combine it with a WHERE threshold.

Geohashes approximate location with a short string that prefixes share when points are nearby, and are useful for rough bucketing and cache keys. SurrealDB provides geo::hash::encode() and geo::hash::decode() for moving between points and geohash strings.

For end-to-end examples that tie these ideas to product features, see Location-based patterns.

Was this page helpful?