Closest facility routing
What is closest facility routing?
Closest facility routing is the process of finding one or more nearby facilities from incidents based on travel time or travel distance. Once you've found the closest facilities, you can display the best route to them and include the travel time, travel distance, and driving directions to each facility in multiple languages.
You can use closest facility routing to build applications that:
- Find the closest hospital to an accident.
- Dispatch the two closest police cars to a crime scene.
- Find the three closest fire stations that can respond to a fire incident within five minutes' drive time.
When finding the closest facilities, you can:
- Specify the number of nearby facilities to find.
- Set the direction of travel toward or away from facilities.
- Apply current traffic conditions to determine the best routes.
- Provide an impedance cutoff beyond which the service should not search for a facility. For instance, you can set up a closest facility service request to search for hospitals within 15 minutes drive time of the site of an accident. Any hospitals that take longer than 15 minutes to reach will not be included in the results.
- Perform multiple closest facility searches simultaneously. This means you can have multiple incidents and find the closest facility or facilities to each incident.
How closest facility routing works
The typical workflow for closest facility routing is to define:
- A set of locations from which to choose the nearest locations (facilities).
- One or more locations from which to start searching for the nearby locations (incidents).
- The type of travel for the analysis.
- The number of closest facilities to find per incident.
- Call the service to find the closest facilities and generate route and directions to each nearby facility.
URL requests
You can perform closest facility routing by making an HTTPS request to the closest facility service solve
operation or by using client APIs. Specify the facilities to search for, one or more incidents, and optionally, additional parameters to refine the operation. Some of most common parameters are described below.
Request limits
Limit | Direct | Job |
---|---|---|
Maximum number of incidents: | 100 | 5,000 |
Maximum number of facilities: | 100 | 5,000 |
Maximum number of facilities to find (per incident): | 10 | 100 |
Maximum transaction time: | 5 minutes | 60 minutes |
Maximum number of point barriers: | 250 | 250 |
Maximum number of street features intersected by polyline barriers: | 500 | 500 |
Maximum number of street features intersected by polygon barriers: | 2,000 | 2,000 |
Maximum straight-line distance for the walking travel mode: (If the straight-line distance between any incidents or facilities is greater than this limit, the analysis will fail when the walking restriction is used.) | 27 miles (43.45 kilometers) | 27 miles (43.45 kilometers) |
Force hierarchy beyond a straight-line distance of: (If the straight-line distance between any incidents or facilities is greater than the limit shown here, the analysis uses hierarchy, even if the travel mode defines not to use hierarchy.) | 50 miles (80.46 kilometers) | 50 miles (80.46 kilometers) |
Maximum snap tolerance: (If the distance between an input point and its nearest traversable street is greater than the distance specified here, the point is excluded from the analysis.) | 12.42 miles (20 kilometers) | 12.42 miles (20 kilometers) |
Maximum number of directions features that can be returned: | No limit | 1,000,000 |
Required parameters
Name | Description | Examples |
---|---|---|
f | The format of the data returned. | f=json f=pjson |
token | An API key or OAuth 2.0 access token. Learn how to get an access token in Security and authentication. | token=< token=< |
Direct
Use for shorter transactions to find up to 10 facilities from 100 facilities and 100 incidents in less than 5 minutes.
Key parameters
Name (Direct) | Description | Examples |
---|---|---|
facilities | Set of locations from which to choose the nearest locations. | facilities=-117.190774,34.057301;-117.199781,34.06047 |
incidents | One or more locations from which to start searching for the nearby locations. | incidents=-117.195696,34.056503 |
travel | The mode of transportation such as driving a car or a truck or walking. | travel JSON Object |
default | The number of closest facilities to find per incident. | default |
default | The travel time or travel distance value at which to stop searching for facilities for a given incident. | default |
travel | Whether you want to search for the closest facility as measured from the incident to the facility or from the facility to the incident. | travel |
Additional parameters: Set additional constraints when finding closest facilities such as time
to use live traffic conditions or return
and directions
to generate driving directions to each nearby facility.
Job
Use for longer transactions to find up to 100 facilities from 5,000 facilities and 5,000 incidents in less than 60 minutes.
Key parameters
Name (Direct) | Description | Examples |
---|---|---|
facilities | Set of locations from which to choose the nearest locations. | facilities={"features":[{"geometry":{"x":-117.190774,"y":34.057301}},{"geometry":{"x":-117.199781,"y":34.06047}}]} |
incidents | One or more locations from which to start searching for the nearby locations. | incidents={"features":[{"geometry":{"x":-117.195696,"y":34.056503}}]} |
travel_ | The mode of transportation such as driving a car or a truck or walking. | travel JSON Object |
number_ | The number of closest facilities to find per incident. | number_ |
cutoff | The travel time or travel distance value at which to stop searching for facilities for a given incident. | cutoff=5 |
travel_ | Whether you want to search for the closest facility as measured from the incident to the facility or from the facility to the incident. | travel_ |
Additional parameters: Set additional constraints when finding closest facilities such as time_
to use live traffic conditions or populate_
and directions_
to generate driving directions to each nearby facility.
Code examples
Direct: Find closest grocery stores
In this example, use the Closest facility service to find the three closest grocery stores from a start location and find the best routes to visit the stores.
To find the closest grocery stores, you need to define all grocery stores as facilities
, and a start location, for example an address or your current GPS location as incidents
. The default
value is set to 3 so that the service will find three closest grocery stores from the current location instead of one. You set return
to true
to get the best routes to the closest grocery stores. In order to determine which three grocery stores are nearest from the list of all available grocery stores, you should set the return
to true
so that you can correlate the chosen grocery stores from the returned facilities and routes.
The response contains the best routes to the three closest grocery stores as well as all the grocery stores provided as input. In order to find the three closest grocery stores, you can match the Facility
field in routes
with the Object
field in facilities
.
APIs
REST API
Job: Find closest fire stations
In this example, you will find the two fire stations that can provide the quickest response to a fire at a given address. You will also generate routes and driving directions for the firefighters.
All the fire stations in the neighborhood are specified as the facilities
parameter, and the location of the fire is specified as the incidents
parameter. To include the name of the fire station in the driving directions, you should specify Name
field in the facilities
. Because you want to model the fire engines traveling from the stations to the location of the fire, you specify Facility to Incident
as the value for the travel_
parameter. You need to find the two closest fire stations within five minutes of the fire, so specify 2
as the value for the number_
parameter and 5
as the value for the cutoff
parameter. You need to calculate the best routes that account for the current traffic conditions, so specify the current time in milliseconds since epoch as the time_
parameter and specify Start Time
as the time_
parameter. Specify populate_
parameter in order to generate the driving directions.
APIs
REST API
Unlike Direct request type which allows you to make a request and get back all the results in the response, when working with a Job request type, you need to follow a three step workflow:
- Make the
submit
request with the appropriate request parameters to get a job id.Job - Using the job id, check the job status to see if the job completed successfully.
- Use the job id to get one or more results.
Tutorials

Find a route and directions
Find a route and directions with the routing service.

Find service areas
Create an isochrone with driving distance with the routing service.
Services
Routing service
Get turn-by-turn directions and solve advanced routing problems.
API support
Routing | Optimized Routing | Fleet routing | Closest facility routing | Service areas | Location-allocation | Travel cost matrix | |
---|---|---|---|---|---|---|---|
ArcGIS Maps SDK for JavaScript | 1 | 1 | 1 | ||||
ArcGIS Maps SDK for .NET | 1 | 1 | 1 | ||||
ArcGIS Maps SDK for Kotlin | 1 | 1 | 1 | ||||
ArcGIS Maps SDK for Swift | 1 | 1 | 1 | ||||
ArcGIS Maps SDK for Java | 1 | 1 | 1 | ||||
ArcGIS Maps SDK for Qt | 1 | 1 | 1 | ||||
ArcGIS API for Python | |||||||
ArcGIS REST JS | |||||||
Esri Leaflet | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
MapLibre GL JS | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
OpenLayers | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
- 1. Access with geoprocessing task.
- 2. Access via ArcGIS REST JS.
Tools
Developer dashboard
Manage API keys, service usage, and data with the ArcGIS Developers website.
ArcGIS Online
Create, manage, and share content and data with cloud-based GIS tools.
Map Viewer
Create, explore, and share web maps for 2D applications.
Scene Viewer
Create, explore, and share web scenes for 3D applications.
ArcGIS Pro
Explore, visualize, and analyze both 2D and 3D data with desktop GIS tools.