Introduction to finding a route and directions

Routing is the process of finding the best path from an origin to a destination in a street network. Routing takes into consideration many different data parameters in the street network such as speed limit, number of lanes, and time of day. Routing can also take into consideration other real-time data such as road conditions, accidents, and other barriers.

You can use the routing service to:

  • Find the shortest path from an origin to a destination.
  • Find the quickest path to multiple destinations.
  • Determine the best sequence to visit multiple destinations.
  • Generate driving directions in multiple languages.

How to access the routing service

There is no direct integration in Esri Leaflet to access the routing service. To access the service in your application, you use the routing and request packages from ArcGIS REST JS in addition to the Esri Leaflet plugin.

Steps

The typical steps for accessing the routing service with ArcGIS REST JS is to:

  1. Reference the Esri Leaflet plugin.
  2. Reference the appropriate ArcGIS REST JS package.
  3. Set the API key to authenticate the request.
  4. Define parameters to pass to the service.
  5. Call the service and handle the results.

Example

Find a route

In this example, you use the Esri Leaflet plugin in addition to ArcGIS REST JS to find a route between two points.

Use dark colors for code blocks
                          
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

<script src="https://unpkg.com/esri-leaflet@3.0.8/dist/esri-leaflet.js"
    integrity="sha512-oUArlxr7VpoY7f/dd3ZdUL7FGOvS79nXVVQhxlg6ij4Fhdc4QID43LUFRs7abwHNJ0EYWijiN5LP2ZRR2PY4hQ=="
    crossorigin=""></script>

<script
  src="https://unpkg.com/@esri/arcgis-rest-request@4.0.2/dist/bundled/request.umd.min.js"
  integrity="sha512-9Q977kmOqSCe/ClsYEWydCwneAHm6shnkRHga25f1R5HnnnGovB5nxtGqosYLfrMIIj6wDBSUfvkOyIC5Ph7bg==">
</script>

<script
  src="https://unpkg.com/@esri/arcgis-rest-routing@4.0.1/dist/bundled/routing.umd.min.js"
  integrity="sha512-MisDmTOSyN6FtMUUvJ7mtU2ZOQV9moszfT/xLRpijhfqwoBd9nYBUZD8KWSbb/VYfvcmxS9SMc+nQigMk/j0pg==">
</script>

<script>
arcgisRest
  .solveRoute({
    stops: [startCoords, endCoords],
    endpoint: "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve",
    authentication
  })
  .then((response) => {
    console.log(response)
  });
</script>

Learn more in the Find a route and directions tutorial.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.