Route and directions

A route and turn-by-turn directions for two points created with the routing service

What is routing?

Routing, also known as simple routing, is the process of finding the best path from an origin to a destination for an individual or single vehicle. 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 routing to build applications that:

  • Find the shortest path from an origin to a destination
  • Find the quickest path to multiple destinations
  • Generate driving directions in multiple languages

How routing works

The typical workflow for creating a route is to:

  1. Define the origin, and stops, and destination.
  2. Define the type of travel for the route.
  3. Call the service to find the route features and directions.

You can create simple or optimized routes using the routing service.

  • A simple route is the shortest path between stops.

  • An optimized route is the most efficient path between stops.

To create an optimized route, you will need to use the findBestSequence parameter. Using the parameter will result in the stops being reordered to return the most efficient path between them.

How to navigate a route

Once you have a route, if you want to use your current device's location to track progress and provide navigation instructions (voice guidance) as you traverse the route, the best way to accomplish this is with the ArcGIS Maps SDKs for Native Apps.

URL requests

You can find a route and directions by making an HTTPS request to the routing service solve operation or by using client APIs. Specify the origin, destination, and optionally, additional parameters to refine the results with directions. Some of the most common parameters are described provided below.

Required parameters

NameDescriptionExamples
fThe format of the data returned.f=json f=pjson f=geojson f=html
tokenAn API key or OAuth 2.0 access token. Learn how to get an access token in Security and authentication.token=<YOUR_API_KEY>
token=<ACCESS_TOKEN>
stopsThe two or more locations that need to be visited in the route.stops=-117,34; -117.5,34.5
findBestSequenceSpecify whether the service should find the best sequence when visiting multiple destinations. Note: Set this parameter to true to generate an optimized route.findBestSequence=true

Direct

Use for shorter transactions with less than 150 stops that will complete in less than 5 minutes.

Use dark colors for code blocksCopy
1
https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve?<parameters>
Use dark colors for code blocksCopy
1
https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve?<parameters>

Key parameters

Name (Direct)DescriptionExamples
travelModeThe mode of transportation such as driving a car or a truck or walking.travelMode=JSON Object
startTimeThe time at which travel begins from the input stops. You can also specify a value of now, to set the depart time to the current time.startTime=now
returnDirectionsGenerate driving directions for each route.returnDirections=true
directionsLanguageThe language to be used when generating driving directions.directionsLanguage=es

Additional parameters: Set additional constraints for a route such as temporary slowdowns, using polygonBarriers, or set outputLines to specify the type of route feature created by the service.

Job

Use for longer transactions with up to 10,000 stops that will complete in less than 60 minutes.

Use dark colors for code blocksCopy
1
https://logistics.arcgis.com/arcgis/rest/services/World/Route/GPServer/FindRoutes/submitJob?<parameters>

Required parameters

NameDescriptionExamples
fThe format of the data returned.f=json f=pjson f=geojson f=html
tokenAn API key or OAuth 2.0 access token. Learn how to get an access token in Security and authentication.token=<YOUR_API_KEY>
token=<ACCESS_TOKEN>
stopsThe two or more locations that need to be visited in the route.stops=-117,34; -117.5,34.5
reorder_stops_to_find_optimal_routesSpecify whether the service should find the best sequence when visiting multiple destinations. Note:Set this parameter to true to return an optimized route.reorder_stops_to_find_optimal_routes=true

Key parameters

Name (Job)DescriptionExamples
travel_modeThe mode of transportation such as driving a car or a truck or walking.travel_mode=JSON Object
time_of_dayThe time at which travel begins from the input stops.time_of_day=1608022800000
populate_directionsGenerate driving directions for each route.populate_directions=true
directions_languageThe language to be used when generating driving directions.directions_language=es

Additional parameters: Set additional constraints such as temporary slowdowns, using polygon_barriers, route_shape to specify the type of route feature created by the service, or set return_to_start if the start and end location for your route is same.

Code examples

Direct: Find a route and directions

In this example, use the routing service to find a route between a set of stops that accounts for current traffic conditions and generate driving directions in Spanish.

To find a route, you need to define at least two stops to visit. The default travelMode is driving time by vehicle, but you can use walk or trucking travel modes as well. It is always good to provide the startTime to get the best results. In this example, we specify startTime as now which sets the route departure time as the current time and also indicates to the service that the route should use the current traffic conditions. We also set the directionsLanguage to generate driving directions in our language of choice.

The response contains a set of ordered stops to visit, the route segments, and turn-by-turn text directions.

APIs

ArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for .NETArcGIS Maps SDK for SwiftArcGIS Maps SDK for KotlinArcGIS Maps SDK for JavaArcGIS Maps SDK for Qt (C++)ArcGIS Maps SDK for Qt (QML)ArcGIS API for PythonArcGIS REST JSEsri LeafletMapLibre GL JSOpenLayersCesiumJS
Expand
Use dark colors for code blocksCopy
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
      function getRoute() {

        const routeUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World";

        const routeParams = new RouteParameters({
          stops: new FeatureSet({
            features: view.graphics.toArray()
          }),
          returnDirections: true,
          directionsLanguage: "es"
        });

        route.solve(routeUrl, routeParams)
          .then((data)=> {
            if (data.routeResults.length > 0) {
              showRoute(data.routeResults[0].route);
              showDirections(data.routeResults[0].directions.features);
            }
          })
          .catch((error)=>{
            console.log(error);
          })
      }

REST API

cURLcURLHTTP
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
curl https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve? \
-d "f=json"
-d "token=<ACCESS_TOKEN>"
-d "stops=-122.68782,45.51238;-122.690176,45.522054;-122.614995,45.526201"
-d "startTime=now"
-d "returnDirections=true"
-d "directionsLanguage=es"

Job: Find multiple routes

In this example, you will find the travel time and travel distance for multiple routes operated by a long-haul logistics company.

  • We group a pair of stops that define a route by assigning them a unique RouteName value. This allows the service to find all the routes in a single request as compared to sending multiple requests for each route, thus improving the overall performance.

  • We specify the Trucking Time travel_mode since we are finding routes for trucks and not cars.

  • Since we are only interested in finding the travel time and travel distance for our routes and do not need the route geometry, we set the route_shape to None.

  • We also do not need driving directions for our routes. So we set the populate_directions to false.

APIs

ArcGIS API for Python
Expand
Use dark colors for code blocksCopy
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
    # Connect to the routing service
    api_key = "YOUR_API_KEY"
    arcgis.GIS("https://www.arcgis.com", api_key=api_key)

    # Get the trucking time travel mode defined for the portal. Fail if the travel mode is not found.
    truck_time_travel_mode = ""
    for feature in arcgis.network.analysis.get_travel_modes().supported_travel_modes.features:
        attributes = feature.attributes
        if attributes["AltName"] == "Trucking Time":
            truck_time_travel_mode = attributes["TravelMode"]
            break
    assert truck_time_travel_mode, "Trucking Time travel mode not found"

    # Call the routing service
    result = arcgis.network.analysis.find_routes(stops=stops,
                                                 travel_mode=truck_time_travel_mode,
                                                 populate_directions=False,
                                                 route_shape="None")
    print_result(result)

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:

  1. Make the submitJob request with the appropriate request parameters to get a job id.
  2. Using the job id, check the job status to see if the job completed successfully.
  3. Use the job id to get one or more results.
cURLcURLHTTP
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
curl https://logistics.arcgis.com/arcgis/rest/services/World/Route/GPServer/FindRoutes/submitJob? \
-d "f=json" \
-d "token=<ACCESS_TOKEN>" \
-d "stops={'features':[{'geometry':{'x':-118.268579,'y':34.052291},'attributes':{'Name':'Los Angeles, CA','RouteName':'Route A'}},{'geometry':{'x':-74.009023,'y':40.709975},'attributes':{'Name':'New York, NY','RouteName':'Route A'}},{'geometry':{'x':-87.648549,'y':41.758688},'attributes':{'Name':'Chicago, IL','RouteName':'Route B'}},{'geometry':{'x':-122.320028,'y':47.591046},'attributes':{'Name':'Seattle, WA','RouteName':'Route B'}},{'geometry':{'x':-71.057477,'y':42.359483},'attributes':{'Name':'Boston, MA','RouteName':'Route C'}},{'geometry':{'x':-95.368848,'y':29.759222},'attributes':{'Name':'Houston, TX','RouteName':'Route C'}},{'geometry':{'x':-80.220762,'y':25.761156},'attributes':{'Name':'Miami, FL','RouteName':'Route D'}},{'geometry':{'x':-122.651334,'y':45.51567},'attributes':{'Name':'Portland, OR','RouteName':'Route D'}},{'geometry':{'x':-112.074247,'y':33.446554},'attributes':{'Name':'Phoenix, AZ','RouteName':'Route E'}},{'geometry':{'x':-75.161557,'y':39.952057},'attributes':{'Name':'Philadelphia, PA','RouteName':'Route E'}}]}" \
-d "travel_mode={'attributeParameterValues':[{'attributeName':'Use Preferred Truck Routes','parameterName':'Restriction Usage','value':'PREFER_HIGH'},{'attributeName':'Avoid Unpaved Roads','parameterName':'Restriction Usage','value':'AVOID_HIGH'},{'attributeName':'Avoid Private Roads','parameterName':'Restriction Usage','value':'AVOID_MEDIUM'},{'attributeName':'Driving a Truck','parameterName':'Restriction Usage','value':'PROHIBITED'},{'attributeName':'Roads Under Construction Prohibited','parameterName':'Restriction Usage','value':'PROHIBITED'},{'attributeName':'Avoid Gates','parameterName':'Restriction Usage','value':'AVOID_MEDIUM'},{'attributeName':'Avoid Express Lanes','parameterName':'Restriction Usage','value':'PROHIBITED'},{'attributeName':'Avoid Carpool Roads','parameterName':'Restriction Usage','value':'PROHIBITED'},{'attributeName':'Avoid Truck Restricted Roads','parameterName':'Restriction Usage','value':'AVOID_HIGH'},{'attributeName':'TruckTravelTime','parameterName':'Vehicle Maximum Speed (km/h)','value':0}],'description':'Models basic truck travel by preferring designated truck routes, and finds solutions that optimize travel time. Routes must obey one-way roads, avoid illegal turns, and so on. When you specify a start time, dynamic travel speeds based on traffic are used where it is available, up to the legal truck speed limit.','distanceAttributeName':'Kilometers','id':'ZzzRtYcPLjXFBKwr','impedanceAttributeName':'TruckTravelTime','name':'Trucking Time','restrictionAttributeNames':['Avoid Carpool Roads','Avoid Express Lanes','Avoid Gates','Avoid Private Roads','Avoid Truck Restricted Roads','Avoid Unpaved Roads','Driving a Truck','Roads Under Construction Prohibited','Use Preferred Truck Routes'],'simplificationTolerance':10,'simplificationToleranceUnits':'esriMeters','timeAttributeName':'TruckTravelTime','type':'TRUCK','useHierarchy':true,'uturnAtJunctions':'esriNFSBNoBacktrack'}" \
-d "populate_directions=false" \
-d "route_shape=None" \
Response (JSON)
Use dark colors for code blocksCopy
1
2
3
4
{
  "jobId": "j2b41de060e5d42d082b888d3be029253",
  "jobStatus": "esriJobSubmitted"
}

Tutorials

Services

Routing service

Get turn-by-turn directions and solve advanced routing problems.

API support

RoutingOptimized RoutingFleet routingClosest facility routingService areasLocation-allocationTravel cost matrix
ArcGIS Maps SDK for JavaScript111
ArcGIS Maps SDK for .NET111
ArcGIS Maps SDK for Kotlin111
ArcGIS Maps SDK for Swift111
ArcGIS Maps SDK for Java111
ArcGIS Maps SDK for Qt111
ArcGIS API for Python
ArcGIS REST JS
Esri Leaflet2222222
MapLibre GL JS2222222
OpenLayers2222222
Full supportPartial supportNo support
  • 1. Access with geoprocessing task.
  • 2. Access via ArcGIS REST JS.

Tools

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