Appearance
Distance Filter
The Distance Filter node filters rows by geographic proximity to a center point using the Haversine formula. It supports both kilometers and miles and automatically sorts results by distance (nearest first).
Configuration
| Property | Type | Default | Description |
|---|---|---|---|
latField | string | lat | The field name containing the row's latitude. |
lngField | string | lng | The field name containing the row's longitude. |
centerLat | number | 0 | Latitude of the center point. |
centerLng | number | 0 | Longitude of the center point. |
maxDistance | number | 50 | Maximum distance from the center point. |
unit | string | km | Distance unit: km (kilometers) or miles. |
Input
Accepts a single object or an array of rows. Each row must have latitude and longitude fields.
Output
Returns rows within the specified distance, with an added _distance field (rounded to 2 decimal places). Results are sorted by distance ascending (nearest first).
json
[
{ "id": 1, "name": "Store A", "lat": 48.8566, "lng": 2.3522, "_distance": 0.42 },
{ "id": 2, "name": "Store B", "lat": 48.8606, "lng": 2.3376, "_distance": 1.15 }
]Rows with lat: 0, lng: 0 are excluded from results.
How It Works
- For each input row, the node reads the latitude and longitude from the configured fields.
- It calculates the great-circle distance using the Haversine formula:
- Earth radius: 6,371 km or 3,959 miles.
- Rows within
maxDistanceare kept; others are discarded. - The
_distancefield is added to each surviving row. - Results are sorted by
_distanceascending.
The Haversine Formula
The Haversine formula calculates the shortest distance between two points on a sphere:
a = sin^2(dlat/2) + cos(lat1) * cos(lat2) * sin^2(dlng/2)
distance = radius * 2 * arcsin(sqrt(a))This provides accurate distances for typical use cases (store locators, delivery zones).
Example Use Cases
Store locator within 25 km
latField: "latitude"
lngField: "longitude"
centerLat: 48.8566
centerLng: 2.3522
maxDistance: 25
unit: "km"Delivery zone check (10 miles)
latField: "lat"
lngField: "lng"
centerLat: 40.7128
centerLng: -74.0060
maxDistance: 10
unit: "miles"Dynamic center from user input
Use expressions in config to set the center from form inputs or upstream data:
centerLat: "`{ {input.user_lat}}`"
centerLng: "`{ {input.user_lng}}`"
maxDistance: 50
unit: "km"Full pipeline for a location search
Table Query (locations) --> Distance Filter (center from form) --> Limit (count: 20) --> ResultTIP
Store latitude and longitude as separate numeric columns in your database table. The Distance Filter works on in-memory data, so fetch all candidate rows first (with a generous bounding box if needed), then filter by distance.