Using the routing service A routing service is a service that uses network analysis and streets data to calculate the most effective path and turn-by-turn directions on a street network, optimize fleet routing and deliveries, find the closest facilities, calculate service areas, and more. It is hosted by Esri as the ArcGIS Routing service and can also be hosted in ArcGIS Enterprise. Learn more , your own route services A service, also known as an ArcGIS service, is software that supports an ArcGIS REST API and provides geospatial functionality or data. A service can be hosted by Esri or in ArcGIS Enterprise. Learn more , or a route dataset stored on the device A device is nearly any kind of computer, including desktops, laptops, mobile phones, and tablets. Learn more , you can find routes A route is a polyline that defines the best path between two or more points in a street network. Learn more , directions, and perform advanced analyses on street networks. You can solve network problems such as finding the closest emergency vehicle or facility, identifying a service area A service area is a polygon representing the distance that can be reached within a specified length of time while traveling in a street network. Learn more around a location A location is a position or region (point, line, or polygon) on the earth's surface. Learn more , or servicing a set of orders with a fleet of vehicles.

Your routing app can do things like:

  • Calculate point-to-point and multi- stop A stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more routes A route is a polyline that defines the best path between two or more points in a street network. Learn more
  • Optimize the results to find the shortest or the fastest route
  • Find the best sequence between stops A stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more
  • Create routes based on the travel mode A travel mode is the means of transportation, such as walking or driving, that defines how you can travel in a street network. Learn more (driving, cycling, walking, and so on)
  • Avoid restricted areas and maneuvers
  • Specify time windows of arrival and departure for each stop A stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more
  • Generate driving directions in multiple languages

What is routing?

Routing is the process of finding the best path between two or more stops A stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more in a street network. A common use case is to find a route A route is a polyline that defines the best path between two or more points in a street network. Learn more between two stops, from an origin An origin is a point that defines the start of a route. Learn more to a destination A destination is a point that defines the final stop in a route. Learn more . Routing takes into consideration many different attributes Attributes are fields and values for a single feature or non-spatial record. They are typically stored in a database or service such as a feature service. Learn more in the street network such as speed limit, number of lanes, and time of day. Routing can also incorporate real-time data such as road conditions, accidents, street closures, and other restrictions to travel.

In addition to the routing described above, functionality is provided to analyze street networks. This includes the ability to create service areas A service area is a polygon representing the distance that can be reached within a specified length of time while traveling in a street network. Learn more (to find customers within a certain drive time, for example) or locate a closest facility (nearest hospital to an accident, for example).

Directions

If requested, directions are returned for each route A route is a polyline that defines the best path between two or more points in a street network. Learn more in the results. Directions provide specific instructions for traveling the route. These are often referred to as “driving directions”, but depending on the travel mode A travel mode is the means of transportation, such as walking or driving, that defines how you can travel in a street network. Learn more , could describe walking or cycling to the destination A destination is a point that defines the final stop in a route. Learn more . Depending on the services A service, also known as an ArcGIS service, is software that supports an ArcGIS REST API and provides geospatial functionality or data. A service can be hosted by Esri or in ArcGIS Enterprise. Learn more configuration, directions can be returned in more than one language. Supported languages for a service are available in the service metadata.

Directions are composed of maneuvers. Each maneuver contains properties such as the direction text, which contains instructions that describe travel through a section of a route A route is a polyline that defines the best path between two or more points in a street network. Learn more . A direction maneuver is further broken down into maneuver messages that give details about a specific maneuver.

If supported by the service A service, also known as an ArcGIS service, is software that supports an ArcGIS REST API and provides geospatial functionality or data. A service can be hosted by Esri or in ArcGIS Enterprise. Learn more , direction maneuver’s can include from level and to level values to define things like floor levels inside a building. For example, a user may want to see just one level of a walking route A route is a polyline that defines the best path between two or more points in a street network. Learn more that spans multiple floors.

The navigation API allows you to further enhance the routing experience using the current device location A location is a position or region (point, line, or polygon) on the earth's surface. Learn more to track progress and provide navigation instructions (maneuvers) as the user travels the route A route is a polyline that defines the best path between two or more points in a street network. Learn more . You can integrate driving directions with your device’s text-to-speech capability and automatically recalculate a new route when the user leaves the current one.

The route tracker object provides the following functionality using the current device location A location is a position or region (point, line, or polygon) on the earth's surface. Learn more and an appropriate route A route is a polyline that defines the best path between two or more points in a street network. Learn more result:

  • Progress information relative to the next stop A stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more , to the next maneuver, or along the entire route
  • Guidance for navigation as it’s needed (when approaching a maneuver, for example)
  • Automatic recalculation of a route A route is a polyline that defines the best path between two or more points in a street network. Learn more if the device location A location is a position or region (point, line, or polygon) on the earth's surface. Learn more goes off route

How routing works

Online and local routing both rely on a transportation network to model travel. These networks are created from features A feature is a single record, also known as a row, that represents a real-world entity. It typically contains a geometry (point, multipoint, polyline, or polygon) and attributes but it can also contain just attributes. Learn more (lines and points) that represent roads, bridges, tunnels, bike paths, train tracks, and other entities in the network. The geometric intersections of features help to define connectivity between the network entities they represent. The connectivity of the transportation network, along with resistance to travel (speed limit, for example) and other network properties, is analyzed to solve routing problems.

Network Analyst services A service, also known as an ArcGIS service, is software that supports an ArcGIS REST API and provides geospatial functionality or data. A service can be hosted by Esri or in ArcGIS Enterprise. Learn more are hosted in ArcGIS or can be published on your own ArcGIS servers. These services provide a REST API for clients such as mobile and Web applications. For more information about publishing routing services with ArcGIS Enterprise ArcGIS Enterprise is a GIS mapping, analytics, data hosting, and content management product that can be hosted on-premise or in a cloud infrastructure. It includes software, applications, tools, APIs, and services for users and developers. Learn more , see Publish routing services.

You can create a transportation network using ArcGIS Pro ArcGIS Pro is a professional desktop GIS application that can explore, visualize, analyze, and manage 2D and 3D data. Learn more and deploy it to your device using either a mobile map package A mobile map package (MMPK) is a standalone file that contains one or more map definitions, including the basemap layers, data layers, layer styles, and pop-up styles for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more file (.mmpk), a mobile scene package A mobile scene package (MSPK) is a standalone file that contains one or more scene definitions, including the basemap layers, elevation layers, data layers, layer styles, and pop-up styles for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more file (.mspk), or a mobile geodatabase A mobile geodatabase (.geodatabase) is a spatial data storage format in a single file on disk that can store, query, and manage spatial and nonspatial data. In applications built with the ArcGIS Maps SDKs for Native Apps, mobile geodatabases can be used in offline workflows when taking maps and features offline from services or in desktop-based scenarios as standalone mobile geodatabases from ArcGIS Pro. Learn more file. The code to work with a local transportation network (stored directly on the device A device is nearly any kind of computer, including desktops, laptops, mobile phones, and tablets. Learn more ) is identical to the code for using a routing service A service, also known as an ArcGIS service, is software that supports an ArcGIS REST API and provides geospatial functionality or data. A service can be hosted by Esri or in ArcGIS Enterprise. Learn more .

If you’d like a ready-to-use and regularly updated network dataset (and locator A locator is an ArcGIS dataset that stores address information and the rules for translating descriptions of places (such as street addresses or place names) into spatial data that can be displayed on a map. Learn more ) for your area of interest, you can license StreetMap Premium data (in mobile map package format). For details, see Add StreetMap Premium data.

Route task

A route task is a network analysis task that is executed asynchronously Asynchronous is a style of programming that involves executing multiple tasks simultaneously rather than sequentially. Learn more . It returns results with details about a route A route is a polyline that defines the best path between two or more points in a street network. Learn more that visits two or more stops A stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more ( locations A location is a position or region (point, line, or polygon) on the earth's surface. Learn more ) within a transportation network. This operation is sometimes referred to as solving a route A route is a polyline that defines the best path between two or more points in a street network. Learn more .

The RouteTask refers to the local transportation network dataset or online service. If solves a Route using the configured RouteParameters and reports the RouteResult.

// Create a RouteTask from an online route service
var routeTask = await RouteTask.CreateAsync(new Uri(
"https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World"));

Route parameters

Route task parameters specify how a route A route is a polyline that defines the best path between two or more points in a street network. Learn more should be found. There are many parameters that let you customize how the route is determined. Parameters include stops A stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more and barriers A barrier is a geometric feature that alters which streets a route can traverse in a street network. Learn more . Other parameters include travel mode A travel mode is the means of transportation, such as walking or driving, that defines how you can travel in a street network. Learn more , whether stops map be reordered to find an optimized route An optimized route is the lowest cost path that visits all stops specified by the user in the most efficient order, regardless of the order in which they are provided. Learn more , the units to be used in the turn-by-turn directions (miles or kilometers, for example), and so on.

To initially create RouteParameters, call RouteTask.makeDefaultParameters() to retrieve the default routing parameters defined for the service. You can then change individual route parameters as needed before executing the RouteTask. The service’s default parameters typically support the most common use case anticipated for that service. Different services can have different defaults.

// Get the route services default parameters
var routeParameters = await routeTask.CreateDefaultParametersAsync();
// Create a list of stops using the graphic's geometry (points)
var stops = new[] {
new Stop((MapPoint)originGraphic.Geometry),
new Stop((MapPoint)intermediateStopGraphic.Geometry),
new Stop((MapPoint)destinationGraphic.Geometry) };
// Add the stops to the route parameters
routeParameters.SetStops(stops);
// Return driving directions in Spanish
routeParameters.ReturnDirections = true;
routeParameters.DirectionsLanguage = "es";

Route results

The results returned from finding a route A route is a polyline that defines the best path between two or more points in a street network. Learn more contain a collection of routes. Each route is represented by a polyline A polyline is a type of geometry containing ordered point coordinates and a spatial reference. Learn more geometry and has information such as its total length and travel time. Depending on how you configured your route parameters, the results may also contain barriers A barrier is a geometric feature that alters which streets a route can traverse in a street network. Learn more , stops A stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more , and driving directions. Typically, the route A route is a polyline that defines the best path between two or more points in a street network. Learn more , stops, and barriers are displayed as graphics A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more in the map A map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more . Directions can be shown in a list or other UI element in the app.

// Solve the route using the route parameters
var routeResult = await routeTask.SolveRouteAsync(routeParameters);
// If a result is returned, display the route
if (routeResult?.Routes?.FirstOrDefault() is Route route)
{
// Show the route as a graphic in the map view
var routeGraphic = new Graphic(route.RouteGeometry);
_routeOverlay.Graphics.Add(routeGraphic);
// Get the driving directions
var directions = string.Join("\n", route.DirectionManeuvers.Select(maneuver => maneuver.DirectionText));
DirectionsTextBlock.Text = directions;
}

Examples

Find a route and directions

Use the routing service A routing service is a service that uses network analysis and streets data to calculate the most effective path and turn-by-turn directions on a street network, optimize fleet routing and deliveries, find the closest facilities, calculate service areas, and more. It is hosted by Esri as the ArcGIS Routing service and can also be hosted in ArcGIS Enterprise. Learn more to find a route A route is a polyline that defines the best path between two or more points in a street network. Learn more between a set of stops A stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more . The result will account for current traffic conditions and provide driving directions in Spanish.

To find a route, you need to define at least two stops to visit. The default travel mode A travel mode is the means of transportation, such as walking or driving, that defines how you can travel in a street network. Learn more is driving, but you can use walk or trucking travel modes as well. It is always good to provide the start time to get the best results (to consider the appropriate traffic conditions, for example). In this example, the start time is set with the current time which indicates to the service that the route should use the current traffic conditions. The directions language is set to “es” to generate driving directions in Spanish.

The result contains a set of ordered stops A stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more to visit, the route segments, and turn-by-turn text directions.

72 collapsed lines
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.Tasks.NetworkAnalysis;
using Esri.ArcGISRuntime.UI;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace ArcGISRuntime.DevGuide.Topics.RoutingIntroduction;
public partial class RoutingIntroduction
{
private GraphicsOverlay _routeOverlay;
private GraphicsOverlay _stopsOverlay;
public RoutingIntroduction()
{
InitializeComponent();
SetupMap();
}
private void SetupMap()
{
// Provide an access token for your app (usually when the app starts).
//Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "YOUR_ACCESS_TOKEN";
MyMapView.Map = new Map(BasemapStyle.ArcGISNavigation);
MyMapView.SetViewpoint(new Viewpoint(
latitude: 45.526201,
longitude: -122.65,
scale: 150000
));
// Create graphics overlays to show routes and stops.
var routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.RebeccaPurple, 2);
var stopSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Red, 14);
_routeOverlay = new GraphicsOverlay { Renderer = new SimpleRenderer(routeSymbol) };
_stopsOverlay = new GraphicsOverlay { Renderer = new SimpleRenderer(stopSymbol) };
// Add the graphics overlays to the map view.
MyMapView.GraphicsOverlays.Add(_routeOverlay);
MyMapView.GraphicsOverlays.Add(_stopsOverlay);
// Solve a route between some predefined stops.
_ = RouteBetweenStops();
}
private async Task RouteBetweenStops()
{
// A graphic to show the start location.
var originGraphic = new Graphic
{
Geometry = new MapPoint(-122.690, 45.522, SpatialReferences.Wgs84)
};
// A graphic to show an intermediate stop.
var intermediateStopGraphic = new Graphic
{
Geometry = new MapPoint(-122.615, 45.526, SpatialReferences.Wgs84)
};
// A graphic to show the final destination
var destinationGraphic = new Graphic
{
Geometry = new MapPoint(-122.688, 45.512, SpatialReferences.Wgs84)
};
// Add graphics to the stops overlay
_stopsOverlay.Graphics.Add(originGraphic);
_stopsOverlay.Graphics.Add(intermediateStopGraphic);
_stopsOverlay.Graphics.Add(destinationGraphic);
// Create a RouteTask from an online route service
var routeTask = await RouteTask.CreateAsync(new Uri(
"https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World"));
// Get the route services default parameters
var routeParameters = await routeTask.CreateDefaultParametersAsync();
// Create a list of stops using the graphic's geometry (points)
var stops = new[] {
new Stop((MapPoint)originGraphic.Geometry),
new Stop((MapPoint)intermediateStopGraphic.Geometry),
new Stop((MapPoint)destinationGraphic.Geometry) };
// Add the stops to the route parameters
routeParameters.SetStops(stops);
// Return driving directions in Spanish
routeParameters.ReturnDirections = true;
routeParameters.DirectionsLanguage = "es";
// Solve the route using the route parameters
var routeResult = await routeTask.SolveRouteAsync(routeParameters);
// If a result is returned, display the route
if (routeResult?.Routes?.FirstOrDefault() is Route route)
{
// Show the route as a graphic in the map view
var routeGraphic = new Graphic(route.RouteGeometry);
_routeOverlay.Graphics.Add(routeGraphic);
// Get the driving directions
var directions = string.Join("\n", route.DirectionManeuvers.Select(maneuver => maneuver.DirectionText));
DirectionsTextBlock.Text = directions;
}
3 collapsed lines
}
}

Use API keys

Tutorials

Samples

Services