The Distance formula calculates the straight-line geographic distance between 2 points on Earth using their latitude and longitude coordinates. Use it to measure proximity between locations in your app, like the distance between a customer site and a warehouse, or whether a delivery address falls within a service radius.
This article covers what you need to know before using the Distance formula function and includes examples for common use cases.
Before you start
Distance is calculated using the haversine formula, which models the Earth as a perfect sphere. Results represent straight-line geographic distance, not driving or travel distance, and may vary slightly from measurements that account for the Earth's true shape.
Coordinates must be provided in decimal degrees. If your app stores coordinates in degrees/minutes/seconds format, convert them before using this formula. Decimal degree values look like 42.3601, not 42°21'36".
Note: Distance returns null if any input coordinate is null. Use the Nz() function if your fields may be empty and you need a numeric result.
Use the Distance formula
Distance accepts either 4 or 5 arguments, depending on whether you want to specify the unit of measurement.
Miles only (default)
Distance(Number lat1, Number lon1, Number lat2, Number lon2)
Miles or kilometers
Distance(Number lat1, Number lon1, Number lat2, Number lon2, Text unit)
Unit must be "miles" or "km". If omitted, the formula returns miles.
Examples
Formula | Result |
|---|---|
| Approximately 190.4 (miles between Boston, MA and New York, NY) |
| Approximately 306.5 (kilometers between Boston, MA and New York, NY) |
| Distance in miles between the customer and warehouse coordinates |
| Distance in kilometers between the delivery location and the depot |
| Distance to Los Angeles rounded to 1 decimal place |
Control decimal places
The Distance formula returns several decimal places by default. Use the Round() function to limit the result to a more readable number.
Round(Distance([lat1], [lon1], [lat2], [lon2]), 1)