How to dispatch the nearest unit automatically, and where distance misleads
An AI employee can match each call to your closest van, crew or depot and alert the desk. How it works, why straight-line distance needs care, and a worked example.
Part of the guide AI employees
To dispatch the nearest unit automatically, you need three things: a position for each call, a list of where your units are based, and a rule that pairs them and tells someone. In xMap Flows the Find nearest block does the pairing. It measures straight-line distance, so it gives a fast, good first answer rather than a guaranteed quickest arrival, and the rest of this page is about using it with that in mind.
This is for the person running a control room or service desk: a lift maintenance firm, a roadside recovery operator, a security patrol company, a utility's fault team. It is not a replacement for a certified emergency dispatch system. Where lives depend on the decision, treat this as a second pair of eyes, with a trained person making the call.
What straight-line distance really tells you
Straight-line distance is the length of a ruler laid on the map between two points. It ignores roads, one-way systems, bridges and traffic. The real drive is usually longer, and the gap is not the same for every unit.
A made-up example shows how this bites. A call comes in on the Pest side of the river in Budapest. Van A is 1.4 km away in a straight line but over in Buda, with the nearest bridge well to the south. Van B is 2.6 km away on the Pest side. Ranked by ruler, A wins. On the road, B could easily get there first.
So use the figure for what it is good at:
- Good for: narrowing a fleet down to two or three candidates, flat cities with dense road grids, and calls where any nearby unit will do.
- Weak near: rivers, railways, motorways with few crossings, hills, ports and city edges.
- Not measured at all: whether a unit is free right now, unless your list says so.
Ask for three candidates, not one
The most useful setting here is how many matches to return. Find nearest can give the closest 1, 2, 3 or 5 points for each call, nearest first. With three, your dispatcher sees the likely choice and the alternatives on one line, and can spot the unit across the river at a glance. You can also set a limit in kilometres, so a call with nothing close reads as uncovered rather than quietly pairing with a van an hour away.
The block names its fields after a short word you choose. Call your points unit and each call gains unit_name, unit_km and the unit's position, along with up to 8 other columns from your file, such as a phone number. The second and third matches carry a name and a distance only.
A worked example: a recovery firm in Johannesburg
Here is an invented operator. Thandi runs twelve recovery trucks from fixed bases around Johannesburg. Drivers ring in incidents, and her controllers have been finding the closest truck by eye on a wall map.
- Keep the bases in a table in My data, with a name, latitude, longitude, driver phone and whether the truck is on shift.
- Start the flow with a Form page the call handler fills in, with a place field for the breakdown's address. The address is looked up, so the call has a position.
- Add Find nearest, reading from the table, with the name unit, the nearest 3, and a limit of 40 km.
- Add a Branch so a call with no unit in range goes to a supervisor instead of the normal queue.
- Add a Slack or WhatsApp message to the controllers' channel: the address, the three candidates with their distances, and the first driver's phone.
- Add Reply, so the handler sees the closest unit on the form page as soon as it is sent.
The controller reads the message, checks the first candidate makes sense, and rings the driver. The flow has done the searching, and a person has made the decision. If you want that step to be formal, put an Approval block before anything goes to the driver.
Keeping positions honest
Find nearest reads the positions in your file or table. It does not track vehicles live. That suits crews who work from fixed bases, depots and stations. For a roaming fleet, the answer is only as fresh as the last update to the table, so if your tracking system can export positions, have it refresh the table often. A van that moved twenty minutes ago is listed in the wrong place until then.
Adding road conditions to the picture
Distance says nothing about what is on the way. Two blocks can add context to a shortlist. Traffic incidents reports closures and roadworks in an area right now, and Traffic Flow gives the live speed and jam factor on roads around each place, so a controller can see that a candidate's base is sitting in heavy traffic. If several jobs are stacking up rather than arriving singly, Route planner is the better tool, since it orders a day's stops by road. More jobs of this kind are in the guide to AI employees for field operations.
Where to start
The Nearest ambulance to each accident template shows the pattern on a timetable: it picks up road incidents in an area and matches each to the nearest of your points. Swap in your own bases and rename the points, then test it against a few past calls where you know which unit should have gone. Those few comparisons will tell you quickly how far the straight line can be trusted in your city.
Questions
Does Find nearest use driving distance?
No, it uses straight-line distance in kilometres. The driving distance is usually longer, so ask for two or three candidates and let a person choose where roads or rivers make a difference.
Can it track my vehicles live?
No. It reads the positions in a CSV or a table in My data. For moving vehicles, keep that table updated from your tracking system.
How many units can I compare against?
A file can hold up to 2,000 points and 12 columns, each with a latitude and longitude.
Should this run an emergency service on its own?
No. It can shortlist units and alert a controller quickly, but decisions that affect safety should stay with a trained person.
Templates that do this
Read next
More on ai employees and automation · Every article · Templates