Finding the nearest ambulance to an incident on the road network map
Matching each road incident to the closest stations, with the distance and a backup, as a planning view for emergency services and private ambulance firms.
Part of the guide Workflow automation
To find the nearest ambulance to an incident, you need two lists with positions: where the incidents are, and where your units or stations are. Matching each incident to the closest one, and the second closest as a backup, is then simple geometry. In xMap Flows the incidents come live from online maps every few minutes, your stations come from a file you upload, and Find nearest does the matching.
This is written for private ambulance and patient transport companies, event medical teams, municipal emergency planners and insurers running roadside assistance. It is a planning and awareness view. It does not replace a dispatch system, which knows each crew's real status, and it does not know about calls from the public.
What the incident data is, and is not
The Traffic incidents block reads road closures, roadworks and other incidents shown on online maps right now, for a city, a drawn area or a circle around a point. Each comes with its kind, the street and district, and a position. Crashes often appear as closures. Nothing in it says how many vehicles were involved or whether anyone is hurt, so treat it as a sign that a stretch of road has a problem, which is exactly what a planner watching coverage needs.
Your side of the match is a simple table: one row per station, depot or standby point, with a name and a latitude and longitude. Columns such as the station's phone or the units based there come along with each match.
How the matching works
Find nearest takes every incident that reaches it and looks up the closest of your points. Its settings are few:
- How many to find: the nearest one, or the nearest 2, 3 or 5, closest first. Two is a good default: the first choice and a backup.
- Only within: a distance in kilometres. A station further away than that is not counted, so incidents beyond your coverage stand out.
- Name of what you match: a short word such as station, which starts the name of every field it adds: station_name, station_km, station_2_name and so on.
A worked example (made up)
Say a private ambulance firm in Madrid covers hospital transfers and two large venues from six bases. The operations lead wants a message whenever a closure or incident appears within the city, with the nearest two bases and how far they are.
- Schedule: every 5 minutes, between 07:00 and 23:00.
- Area of interest: Madrid.
- Traffic incidents over the Area of interest.
- Only new: an incident already reported in an earlier run is left out, so the same closure does not ring every five minutes.
- Find nearest: the six bases from a CSV, the nearest 2, only within 15 km, named base.
- Sort and limit by base_km, closest first.
- Email or a Slack message to the operations channel, and Show on a map with a dashed line from each incident to its nearest base.
A message might read: "Road closure on Calle de Alcala near Retiro. Nearest base: Salamanca, 1.8 km. Backup: Chamartin, 4.1 km." On a night when three incidents cluster in the south while the nearest base is busy with a transfer, the lead can see at once which backup covers them and move a standby crew.
Using the same flow for planning, not just alerts
Run it over a month and the pattern matters more than any single alert. Keep the results, then ask Results in plain words for incidents by district, or have a weekly xMap LLM summary list where incidents most often fall more than 5 km from any base. Those are the areas where a new standby point would shorten the distance most. The Where to stage ambulances in the evening peak template takes this further: it groups the afternoon's incidents into a few staging points near hospitals for dispatch to consider.
Mistakes to avoid
- Reading it as a dispatch tool. It does not know which crews are free. Use it to see coverage and where help is likely to be needed.
- Every incident, every five minutes. Without Only new the same closure repeats all day. Keep it.
- Trusting straight lines in a divided city. Check bases on the far side of rivers, rail lines and motorways with a drive-time area.
- A stale stations file. When a base moves or closes, update the table; the match is only as good as your points.
Starting quickly
The Nearest ambulance to each accident template has the whole flow with eight example stations around the area you choose; replace them with your own file. For the broader picture of AI employees in operations, see the field operations guide.
Questions
Is the distance a driving distance?
No, it is the straight-line distance in kilometres. For a driving view, draw a Travel area around each station or check road speeds with Traffic Flow.
Can I match each incident to more than one station?
Yes. Find nearest can return the nearest 1, 2, 3 or 5 points for every incident, closest first, with a field for each.
Where do my station positions come from?
From a CSV you upload into the block or a table on the My data page, with latitude and longitude columns. The block also offers example points to try the flow first.
Does the incident data include emergency calls?
No. It is road closures, roadworks and incidents shown on online maps, with no information about casualties. It is a view of road problems, not of calls for help.