Calculate Distance Between Addresses
Calculate straight-line and driving distances between addresses or coordinates in a spreadsheet. Build distance matrices across hundreds of locations.
You need to know how far apart two locations are -- the distance between a warehouse and each customer, the nearest store to a given address, or a full distance matrix for route planning. In a regular spreadsheet, this requires an external API or manual lookup.
In GeoSheet, distance is a formula. Type =DISTANCE(A1, B1) and get the answer in kilometers, miles, or meters.
Worked Example: Warehouse to Customer Distances
You have a warehouse address in A1 and customer addresses in column B:
| A | B | |
|---|---|---|
| 1 | 123 Warehouse Rd, Dallas, TX | 456 Oak St, Houston, TX |
| 2 | 789 Pine Ave, Austin, TX | |
| 3 | 321 Elm Blvd, San Antonio, TX | |
| 4 | 654 Maple Dr, Fort Worth, TX |
Straight-line distance
In C1, enter:
=DISTANCE($A$1, B1)
This returns the straight-line (great-circle) distance in kilometers between the warehouse and the first customer. Copy C1 down to C4.
The $A$1 absolute reference keeps the warehouse fixed while each row compares against a different customer.
Change the unit:
=DISTANCE($A$1, B1, "mi") # Miles
=DISTANCE($A$1, B1, "m") # Meters
=DISTANCE($A$1, B1, "km") # Kilometers (default)
Driving distance
For road distance (which accounts for actual roads, not a straight line):
=DRIVE_DISTANCE($A$1, B1)
This returns the driving distance in kilometers via Mapbox routing. The result is typically longer than straight-line distance because roads are not straight.
Building a Distance Matrix
For multiple origins and destinations, you can build a full matrix. Suppose column A has warehouse locations and row 1 has store locations:
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Store 1 (NYC) | Store 2 (Chicago) | Store 3 (LA) | |
| 2 | Warehouse 1 (Dallas) | =DISTANCE($A2, B$1) | =DISTANCE($A2, C$1) | =DISTANCE($A2, D$1) |
| 3 | Warehouse 2 (Atlanta) | =DISTANCE($A3, B$1) | =DISTANCE($A3, C$1) | =DISTANCE($A3, D$1) |
The mixed references ($A2 locks the column, B$1 locks the row) let you fill the entire matrix from one formula.
Tip: Ask Geovani: "Build a distance matrix between all warehouses in column A and all stores in row 1." Geovani handles the formula placement and reference locking.
Finding the Nearest Location
Use NEAREST() to find the closest points:
=NEAREST(A1, B:B, 3)
This returns the 3 nearest points in column B to the point in A1. Useful for "nearest store" or "closest facility" analysis.
How It Works
DISTANCE() computes the Haversine (great-circle) distance between two points on the Earth's surface. It works with POINT values, cell references containing points, or address strings (which are automatically geocoded).
DRIVE_DISTANCE() queries Mapbox Directions to get the actual road distance. This accounts for highways, one-way streets, and road networks. Results are asynchronous -- the cell shows #PENDING briefly while the routing request completes.
NEAREST() computes straight-line distances from a reference point to every point in a range and returns the closest matches.
Both DISTANCE() and DRIVE_DISTANCE() accept addresses directly:
=DISTANCE("New York", "Los Angeles") # ~3,944 km
=DRIVE_DISTANCE("New York", "Los Angeles") # ~4,489 km
Practical Applications
- Delivery radius: Use
=DISTANCE(warehouse, customer) < 50to flag customers within 50 km - Service area analysis: Combine with ISOCHRONE to see which customers fall within a drive-time polygon
- Site selection: Compare average distances from candidate sites to all customers
- Logistics optimization: Build distance matrices to identify the most efficient warehouse-to-customer assignments
Next Steps
- Calculate Drive Time Between Locations -- driving duration, routes, and isochrones
- Map Data in a Spreadsheet -- visualize distances and locations on a map
- Geocode Addresses -- convert addresses to coordinates for distance calculations
- Formulas -- complete formula reference including DISTANCE, DRIVE_DISTANCE, and NEAREST
Updated about 2 months ago