DISTANCE
Calculate the straight-line distance between two geographic coordinates.
Use DISTANCE when you need to measure how far apart two locations are: calculating delivery zones, finding nearby stores, charging based on distance, or filtering options by proximity.
How it works
DISTANCE(lat1, lng1, lat2, lng2)
DISTANCE(lat1, lng1, lat2, lng2, unit)lat1- Latitude of first location (number between -90 and 90)lng1- Longitude of first location (number between -180 and 180)lat2- Latitude of second locationlng2- Longitude of second locationunit- Optional. Unit for the result: "m" (meters), "km" (kilometers), "mi" (miles), "ft" (feet). Defaults to "m"
Returns the distance as a number in the specified unit. Uses the Haversine formula to calculate straight-line distance across the Earth's surface.
DISTANCE calculates "as the crow flies" distance, not driving or walking routes. For straight-line geographic distance only.
Examples
Distance between two cities
Calculate kilometers between Amsterdam and Paris.
DISTANCE(52.3676, 4.9041, 48.8566, 2.3522, "km")Returns approximately 430 kilometers.
Delivery fee based on distance
Charge €5 plus €0.50 per kilometer from your warehouse.
WAREHOUSE_LAT = 52.0907
WAREHOUSE_LNG = 5.1214
CUSTOMER_DISTANCE = DISTANCE(WAREHOUSE_LAT, WAREHOUSE_LNG, CUSTOMER_LAT, CUSTOMER_LNG, "km")
DELIVERY_FEE = 5 + (CUSTOMER_DISTANCE * 0.50)Calculates custom delivery charges based on actual distance.
Find nearby locations
Show only stores within 25 miles of the customer.
STORES | FILTER(STORE:
DISTANCE(CUSTOMER_LAT, CUSTOMER_LNG, STORE_LAT, STORE_LNG, "mi") < 25
)Filters your store list to only nearby options.
Service area check
Determine if a customer is within your 50km service radius.
DISTANCE_TO_CUSTOMER = DISTANCE(OFFICE_LAT, OFFICE_LNG, CUSTOMER_LAT, CUSTOMER_LNG, "km")
IF(DISTANCE_TO_CUSTOMERCommon mistakes
Swapping latitude and longitude - Latitude comes first, longitude second. Amsterdam is (52.37, 4.90) not (4.90, 52.37)
Expecting driving distance - DISTANCE is straight-line only. Actual road distance will be longer
Forgetting unit quotes - Use
"km"notkmfor the unit parameterInvalid coordinates - Latitude must be -90 to 90, longitude -180 to 180
Missing decimal precision - Use enough decimals for accuracy (52.3676 not just 52)
Understanding units
Available distance units:
"m"- Meters (default)"km"- Kilometers"mi"- Miles"ft"- Feet
If you omit the unit parameter, DISTANCE returns meters.