How to sort businesses by distance from a point, nearest first
Sort businesses by distance from an office, a depot or a customer, read the distance column correctly, and know when a road distance tells a different story.
Part of the guide Location intelligence automation
To sort businesses by distance, every business needs a distance from your point written next to it, and then the list is put in order with the smallest number at the top. Searches that look around a point usually give that number already, in metres, and return the nearest first; for your own list, a matching step adds the distance to your nearest office or depot. Just remember that this figure is measured in a straight line, and the drive there can be noticeably longer.
This is for field sales reps planning a day, service companies deciding which jobs a van can reach, buyers looking for the closest suppliers, and anyone who has stared at a list of addresses wondering which ones are actually near. It covers where the distance comes from, how to put the list in order, a worked example, why straight-line and road distances part ways, and how to have the ordering done for you every morning.
Where the distance number comes from
There are three common cases, and each gives the number a slightly different meaning.
- Around one point. Nearby places looks around a position you give, in xMap's places database, and every place it returns carries distance_m, how far it is from that point in metres. The list already comes nearest first.
- Around each of your own places. Run the same search after a list of your stores or sites, and each business found also carries near, the name of the site it was found around, with its distance from that site.
- From each business to your nearest point. Find nearest takes your own points, such as depots, branches or technicians, from a CSV or a table, and gives every business the name of its nearest point and the distance in kilometres, to one decimal. You name the fields, for example depot_name and depot_km.
All three measure as the crow flies. That is quick to work out and fair for comparing places in the same neighbourhood, but it is not the distance a car or a person travels.
Putting the list in order
If the list came from a search around one point, it is already nearest first and you need do nothing. Once other steps reorder or merge it, put the order back with Sort and limit: choose Another field, type the distance field (distance_m, or depot_km from Find nearest), and choose lowest first. You can also keep only the first 20, which turns a long list into a short one.
Two details matter. Items without a distance go to the end whatever the order, so a business with no position never sits at the top by accident. And the order you set is the order the next steps keep: an email lists them in that order, a sheet gets the rows in that order.
A worked example: a print shop's nearest office clients
This example is made up. A print shop in Mexico City wants to visit offices it could serve by bike courier, starting with the closest. It runs Nearby places around the shop's own position for offices and co-working spaces within 2 km, then sorts by distance_m, lowest first, and keeps the first 25.
| Made-up business | distance_m | What the owner noticed |
|---|---|---|
| Co-working space A | 180 | Same street, an easy first visit |
| Architecture office B | 640 | Across a wide avenue with few crossings |
| Agency C | 710 | Next to a bike lane, quick to reach |
| Law office D | 1,950 | Inside a gated business park |
Invented rows to show how the list reads; not data about Mexico City.
On paper, B comes before C. On the ground, the courier reaches C first, because B sits across a wide road with few safe crossings. The sorted list is the right starting point; the owner's knowledge of the streets settles the last few places.
Why a road distance can differ
A straight line ignores everything a traveller has to go around: rivers and the few bridges over them, railways, motorways with no crossing for a kilometre, one-way streets, gated estates. Two businesses 700 m apart on the map can be several kilometres apart by road. The difference grows where water or rail splits a city, and shrinks in a dense grid of streets.
When the real journey matters, measure along the roads. Travel area draws the area reachable within a travel time or a distance by road, by car, bike or on foot, so a search after it keeps only businesses you can really reach in, say, 10 minutes. Route planner puts stops in the best order to visit in a day and gives each one leg_km and leg_min, the road distance and time from the stop before. If the routing service cannot draw an area or a route, the result is an estimate and the step and emails say so.
Mistakes to avoid
- Sorting names, not numbers. Distance stored as text can sort 1,950 before 640. Sort and limit sorts a field as numbers when most of its values are numbers, so keep the unit out of the value.
- Mixing units. distance_m is in metres, Find nearest gives kilometres. Do not sort a list where some rows carry one and some the other.
- Measuring from the wrong point. Around each of your sites, a business is measured from the site in its near field, not from your head office.
- Treating straight lines as travel time. For a delivery promise or a visit plan, use road distances or a travel area.
An AI employee that orders tomorrow's list
For a rep or a van that sets off each morning, the ordering can be done before anyone is awake:
- Schedule: every weekday at 06:30.
- My data: today's accounts or jobs, with their addresses placed on the map.
- Find nearest: each one's nearest depot or technician from your own table, with the distance.
- Route planner: the visits in order for each technician, from their depot, with road distances.
- Email to each person, or a row per stop in a shared sheet.
Each person's inbox holds their stops in order, the distance and time between them, and a directions link for each part of the route. The templates Nearest ambulance to each accident and New outlets on my routes, prioritised, to the nearest rep show the nearest-first idea at work. Teams that dispatch people every day can read more in the AI employee for field operations.
Questions
Is the distance in xMap Flows a road distance?
The distance Nearby places and Find nearest give is a straight line. For distances along the roads, use Travel area or Route planner.
Can I sort by distance and then by rating?
Sort and limit orders by one field at a time. A common way is to filter by distance first, such as within 1 km, and then sort what is left by rating.
What happens to businesses without a position?
They have no distance, so Sort and limit puts them at the end of the list in the order they came in.
How do I keep only the 10 nearest?
In Sort and limit, sort by the distance field, lowest first, and set Keep to a number of your choosing, 10.
Templates that do this
Read next
More on business and places data · Every article · Templates