Route and directions | Documentation | Esri Developer (2024)

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.

Request limits

LimitDirectJob
Maximum number of stops15010,000
Maximum transaction time:5 minutes60 minutes
Maximum number of point barriers:250250
Maximum number of street features intersected by polyline barriers:500500
Maximum number of street features intersected by polygon barriers:2,0002,000
Maximum straight-line distance for the walking travel mode: (If the straight-line distance between any stops 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 stops 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 limit1,000,000
Maximum number of route edges that can be returned:Not available1,000,000

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.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
https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve?<parameters>
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
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.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
 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); }) }

Expand

Go to tutorial

REST API

cURLcURLHTTP
Use dark colors for code blocksCopy
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
 # Connect to the routing service api_key = "YOUR_ACCESS_TOKEN" 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)

Expand

Go to sample

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
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
{ "jobId": "j2b41de060e5d42d082b888d3be029253", "jobStatus": "esriJobSubmitted"}

Tutorials

Route and directions | Documentation | Esri Developer (1)

Find a route and directions

Find a route and directions with the routing service.


JavaScript Maps SDKEsri LeafletMapLibre GL JSOpenLayersCesiumJSREST JSREST API

Route and directions | Documentation | Esri Developer (2024)

References

Top Articles
Latest Posts
Article information

Author: Allyn Kozey

Last Updated:

Views: 6449

Rating: 4.2 / 5 (43 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Allyn Kozey

Birthday: 1993-12-21

Address: Suite 454 40343 Larson Union, Port Melia, TX 16164

Phone: +2456904400762

Job: Investor Administrator

Hobby: Sketching, Puzzles, Pet, Mountaineering, Skydiving, Dowsing, Sports

Introduction: My name is Allyn Kozey, I am a outstanding, colorful, adventurous, encouraging, zealous, tender, helpful person who loves writing and wants to share my knowledge and understanding with you.