Click or drag to resize

RouteParameters Class

Represents parameters used when performing route analysis.
Inheritance Hierarchy

Namespace:  Esri.ArcGISRuntime.Tasks.NetworkAnalysis
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version:
public sealed class RouteParameters

The RouteParameters type exposes the following members.

Public methodRouteParameters
Initializes a new instance of the RouteParameters class.
Public propertyAccumulateAttributeNames
Gets accumulate attribute names.
Public propertyDirectionsDistanceUnits
Gets or sets the directions distance text units.
Public propertyDirectionsLanguage
Gets or sets the directions language.
Public propertyDirectionsStyle
Gets or sets directions style.
Public propertyCode exampleFindBestSequence
Gets or sets the find best sequence flag.
Public propertyCode exampleOutputSpatialReference
Gets or sets the output spatial reference.
Public propertyCode examplePreserveFirstStop
Gets or sets the preserve first stop flag.
Public propertyCode examplePreserveLastStop
Gets or sets the preserve last stop flag.
Public propertyCode exampleReturnDirections
Gets or sets the return directions flag.
Public propertyReturnPointBarriers
Gets or sets the return point barriers flag.
Public propertyReturnPolygonBarriers
Gets or sets the return polygon barriers flag.
Public propertyReturnPolylineBarriers
Gets or sets the return polyline barriers flag.
Public propertyCode exampleReturnRoutes
Gets or sets the return routes flag.
Public propertyCode exampleReturnStops
Gets or sets the return stops flag.
Public propertyRouteShapeType
Gets or sets the route shape type.
Public propertyStartTime
Gets or sets start time in UTC.
Public propertyCode exampleTravelMode
Gets or sets the travel mode.
Public methodClearPointBarriers
Clears point barriers.
Public methodCode exampleClearPolygonBarriers
Clears polygon barriers.
Public methodClearPolylineBarriers
Clears polyline barriers.
Public methodCode exampleClearStops
Clears stops.
Public methodGetSearchWhereClause
Gets the search filter that specifies which network elements stops can be located on.
Public methodSetPointBarriers(IEnumerablePointBarrier)
Sets point barriers.
Public methodSetPointBarriers(ArcGISFeatureTable, QueryParameters)
Sets point barriers with feature table.
Public methodCode exampleSetPolygonBarriers(IEnumerablePolygonBarrier)
Sets polygon barriers.
Public methodSetPolygonBarriers(ArcGISFeatureTable, QueryParameters)
Sets polygon barriers with feature table.
Public methodSetPolylineBarriers(IEnumerablePolylineBarrier)
Sets polyline barriers.
Public methodSetPolylineBarriers(ArcGISFeatureTable, QueryParameters)
Sets polyline barriers with feature table.
Public methodSetSearchWhereClause
Sets a search filter that specifies which network elements stops can be located on.
Public methodCode exampleSetStops(IEnumerableStop)
Sets stops.
Public methodSetStops(ArcGISFeatureTable, QueryParameters)
Sets stops with feature table.


Example Name: OfflineRouting

Solve a route on-the-fly using offline data.

Code example screen shot.

// Copyright 2019 Esri.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific 
// language governing permissions and limitations under the License.

using Android.App;
using Android.OS;
using Android.Widget;
using ArcGISRuntime;
using ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.Tasks.NetworkAnalysis;
using Esri.ArcGISRuntime.UI;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace ArcGISRuntimeXamarin.Samples.OfflineRouting
    [Activity(ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
        "Offline routing",
        "Network Analysis",
        "Solve a route on-the-fly using offline data.",
    public class OfflineRouting : Activity
        // Hold references to the UI controls.
        private MapView _myMapView;
        private TextView _instructionLabel;
        private Spinner _travelModeSpinner;
        private Button _resetButton;

        // Graphics overlays for holding graphics.
        private GraphicsOverlay _stopsOverlay;
        private GraphicsOverlay _routeOverlay;

        // Route task and parameters.
        private RouteTask _offlineRouteTask;
        private RouteParameters _offlineRouteParameters;

        // List of travel modes, like 'Fastest' and 'Shortest'.
        private List<TravelMode> _availableTravelModes;

        // The area covered by the geodatabase used for offline routing.
        private readonly Envelope _routableArea = new Envelope(new MapPoint(-13045352.223196, 3864910.900750, 0, SpatialReferences.WebMercator),
            new MapPoint(-13024588.857198, 3838880.505604, 0, SpatialReferences.WebMercator));

        protected override void OnCreate(Bundle bundle)

            Title = "Offline routing";


        private async void Initialize()
                // Get the paths to resources used by the sample.
                string basemapTilePath = DataManager.GetDataFolder("567e14f3420d40c5a206e5c0284cf8fc", "streetmap_SD.tpk");
                string networkGeodatabasePath = DataManager.GetDataFolder("567e14f3420d40c5a206e5c0284cf8fc", "sandiego.geodatabase");

                // Create the tile cache representing the offline basemap.
                TileCache tiledBasemapCache = new TileCache(basemapTilePath);

                // Create a tiled layer to display the offline tiles.
                ArcGISTiledLayer offlineTiledLayer = new ArcGISTiledLayer(tiledBasemapCache);

                // Create a basemap based on the tile layer.
                Basemap offlineBasemap = new Basemap(offlineTiledLayer);

                // Create a new map with the offline basemap.
                Map theMap = new Map(offlineBasemap);

                // Set the initial viewpoint to show the routable area.
                theMap.InitialViewpoint = new Viewpoint(_routableArea);

                // Show the map in the map view.
                _myMapView.Map = theMap;

                // Create overlays for displaying the stops and the calculated route.
                _stopsOverlay = new GraphicsOverlay();
                _routeOverlay = new GraphicsOverlay();

                // Create a symbol and renderer for symbolizing the calculated route.
                SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Blue, 2);
                _routeOverlay.Renderer = new SimpleRenderer(routeSymbol);

                // Add the stops and route overlays to the map.

                // Create the route task, referring to the offline geodatabase with the street network.
                _offlineRouteTask = await RouteTask.CreateAsync(networkGeodatabasePath, "Streets_ND");

                // Get the list of available travel modes.
                _availableTravelModes = _offlineRouteTask.RouteTaskInfo.TravelModes.ToList();

                // Update the UI with the travel modes list.
                ArrayAdapter<string> spinnerListAdapter = new ArrayAdapter<string>(this,
                    Android.Resource.Layout.SimpleSpinnerItem, _availableTravelModes.Select(travelMode => travelMode.Name).ToArray());
                _travelModeSpinner.Adapter = spinnerListAdapter;

                // Create the default parameters.
                _offlineRouteParameters = await _offlineRouteTask.CreateDefaultParametersAsync();

                // Display the extent of the road network on the map.

                // Now that the sample is ready, hook up the tapped and hover events.
                _myMapView.GeoViewTapped += MapView_Tapped;
                _travelModeSpinner.ItemSelected += TravelMode_SelectionChanged;
            catch (Exception e)
                ShowMessage("Couldn't start sample", "There was a problem starting the sample. See debug output for details.");

        private void DisplayBoundaryMarker()
            // Displaying the boundary marker helps avoid choosing a non-routable destination.
            SimpleLineSymbol boundarySymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.LawnGreen, 5);
            Graphic boundary = new Graphic(_routableArea, boundarySymbol);
            GraphicsOverlay boundaryOverlay = new GraphicsOverlay();

        private void ResetRoute()

        private async void UpdateRoute(TravelMode selectedTravelMode)
                // Create a list of stops.
                List<Stop> stops = new List<Stop>();

                // Add a stop to the list for each graphic in the stops overlay.
                foreach (Graphic stopGraphic in _stopsOverlay.Graphics)
                    Stop stop = new Stop((MapPoint) stopGraphic.Geometry);

                if (stops.Count < 2)
                    // Don't route, there's no where to go (and the route task would throw an exception).

                // Configure the route parameters with the list of stops.

                // Configure the travel mode.
                _offlineRouteParameters.TravelMode = selectedTravelMode;

                // Solve the route.
                RouteResult offlineRouteResult = await _offlineRouteTask.SolveRouteAsync(_offlineRouteParameters);

                // Clear the old route result.

                // Get the geometry from the route result.
                Polyline routeGeometry = offlineRouteResult.Routes.First().RouteGeometry;

                // Note: symbology left out here because the symbology was set once on the graphics overlay.
                Graphic routeGraphic = new Graphic(routeGeometry);

                // Display the route.
            catch (Exception e)
                ShowMessage("Couldn't update route", "There was an error updating the route. See debug output for details. Stop selection has been reset.");

        private async void AddStop(Android.Graphics.PointF tappedPosition)
                // Get the location on the map.
                MapPoint tappedLocation = _myMapView.ScreenToLocation(tappedPosition);

                // Name the stop by its number.
                string stopName = $"{_stopsOverlay.Graphics.Count + 1}";

                // Create a pushpin marker for the stop.
                PictureMarkerSymbol pushpinMarker = await GetPictureMarker();

                // Create the text symbol for labeling the stop.
                TextSymbol stopSymbol = new TextSymbol(stopName, Color.White, 15,
                    HorizontalAlignment.Center, VerticalAlignment.Middle);
                stopSymbol.OffsetY = 15;

                // Create a combined symbol with the pushpin and the label.
                CompositeSymbol combinedSymbol = new CompositeSymbol(new MarkerSymbol[] {pushpinMarker, stopSymbol});

                // Create the graphic from the geometry and the symbology.
                Graphic newStopGraphic = new Graphic(tappedLocation, combinedSymbol);

                // Add the stop to the overlay.
            catch (Exception e)
                ShowMessage("Couldn't select or add stop", "Couldn't select or add stop. See debug output for details.");

        private async Task<PictureMarkerSymbol> GetPictureMarker()
            // Get current assembly that contains the image.
            Assembly currentAssembly = Assembly.GetExecutingAssembly();

            // Get image as a stream from the resources.
            // Picture is defined as EmbeddedResource and DoNotCopy.
            Stream resourceStream = currentAssembly.GetManifestResourceStream(

            // Create new symbol using asynchronous factory method from stream.
            PictureMarkerSymbol pinSymbol = await PictureMarkerSymbol.CreateAsync(resourceStream);
            pinSymbol.Width = 50;
            pinSymbol.Height = 50;
            pinSymbol.LeaderOffsetX = 30;
            pinSymbol.OffsetY = 14;

            return pinSymbol;

        private void ResetButton_Click(object sender, EventArgs e) => ResetRoute();

        private void MapView_Tapped(object sender, GeoViewInputEventArgs e)
            // Make sure the user isn't adding too many stops.
            if (_stopsOverlay.Graphics.Count >= 5)
                ShowMessage("Can't add stop.", "Sample limits to 5 stops per route.");

            // Make sure the stop is valid before proceeding.
            if (!GeometryEngine.Contains(_routableArea, e.Location))
                ShowMessage("Can't add stop.", "That location is outside of the area where offline routing data is available.");

            // Add the stop.

            // Update the route with the final list of stops.
            TravelMode selectedTravelMode = _availableTravelModes[_travelModeSpinner.SelectedItemPosition];

        private void TravelMode_SelectionChanged(object sender, EventArgs e)
                // Get the selected travel mode.
                TravelMode selectedTravelMode = _availableTravelModes[_travelModeSpinner.SelectedItemPosition];

                // Update the route.
            catch (Exception ex)
                ShowMessage("Couldn't change travel mode", "Couldn't change travel mode. See debug output for details.");

        private void ShowMessage(string title, string detail) => new AlertDialog.Builder(this).SetTitle(title).SetMessage(detail).Show();

        private void CreateLayout()
            // Load the layout for the sample from the .axml file.

            // Hook up references to controls.
            _myMapView = FindViewById<MapView>(Resource.Id.OfflineRouting_MyMapView);
            _resetButton = FindViewById<Button>(Resource.Id.OfflineRouting_ResetButton);
            _instructionLabel = FindViewById<TextView>(Resource.Id.OfflineRouting_InstructionLabel);
            _travelModeSpinner = FindViewById<Spinner>(Resource.Id.OfflineRouting_TravelModeSpinner);

            // Set up reset button event.
            _resetButton.Click += ResetButton_Click;

            // Update the label text.
            _instructionLabel.Text = "Tap to add up to 5 stops. The route will display automatically.";

Xamarin Forms Android

Example Name: FindRoute

Display directions for a route between two points.

Code example screen shot.

// Copyright 2017 Esri.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

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.Collections.Generic;
using System.Linq;
using Xamarin.Forms;
using Colors = System.Drawing.Color;

namespace ArcGISRuntime.Samples.FindRoute
        "Find a route",
        "Network Analysis",
        "This sample demonstrates how to solve for the best route between two locations on the map and display driving directions between them.",
    public partial class FindRoute : ContentPage
        // List of stops on the route ('from' and 'to')
        private List<Stop> _routeStops;

        // Graphics overlay to display stops and the route result
        private GraphicsOverlay _routeGraphicsOverlay;

        // URI for the San Diego route service
        private Uri _sanDiegoRouteServiceUri = new Uri("");

        // URIs for picture marker images
        private Uri _checkedFlagIconUri = new Uri("");

        private Uri _carIconUri = new Uri("");

        public FindRoute()

            // Create the map, graphics overlay, and the 'from' and 'to' locations for the route

        private void Initialize()
            // Define the route stop locations (points)
            MapPoint fromPoint = new MapPoint(-117.15494348793044, 32.706506537686927, SpatialReferences.Wgs84);
            MapPoint toPoint = new MapPoint(-117.14905088669816, 32.735308180609138, SpatialReferences.Wgs84);

            // Create Stop objects with the points and add them to a list of stops
            Stop stop1 = new Stop(fromPoint);
            Stop stop2 = new Stop(toPoint);
            _routeStops = new List<Stop> { stop1, stop2 };

            // Picture marker symbols: from = car, to = checkered flag
            PictureMarkerSymbol carSymbol = new PictureMarkerSymbol(_carIconUri);
            PictureMarkerSymbol flagSymbol = new PictureMarkerSymbol(_checkedFlagIconUri);

            // Add a slight offset (pixels) to the picture symbols.
            carSymbol.OffsetX = -carSymbol.Width / 2;
            carSymbol.OffsetY = -carSymbol.Height / 2;
            flagSymbol.OffsetX = -flagSymbol.Width / 2;
            flagSymbol.OffsetY = -flagSymbol.Height / 2;

            // Set the height and width.
            flagSymbol.Height = 60;
            flagSymbol.Width = 60;
            carSymbol.Height = 60;
            carSymbol.Width = 60;

            // Create graphics for the stops
            Graphic fromGraphic = new Graphic(fromPoint, carSymbol) { ZIndex = 1 };
            Graphic toGraphic = new Graphic(toPoint, flagSymbol) { ZIndex = 1 };

            // Create the graphics overlay and add the stop graphics
            _routeGraphicsOverlay = new GraphicsOverlay();

            // Get an Envelope that covers the area of the stops (and a little more)
            Envelope routeStopsExtent = new Envelope(fromPoint, toPoint);
            EnvelopeBuilder envBuilder = new EnvelopeBuilder(routeStopsExtent);

            // Create a new viewpoint apply it to the map view when the spatial reference changes
            Viewpoint sanDiegoViewpoint = new Viewpoint(envBuilder.ToGeometry());
            MyMapView.SpatialReferenceChanged += (s, e) => MyMapView.SetViewpoint(sanDiegoViewpoint);

            // Add a new Map and the graphics overlay to the map view
            MyMapView.Map = new Map(Basemap.CreateStreets());

        private async void SolveRouteClick(object sender, EventArgs e)
                // Create a new route task using the San Diego route service URI
                RouteTask solveRouteTask = await RouteTask.CreateAsync(_sanDiegoRouteServiceUri);

                // Get the default parameters from the route task (defined with the service)
                RouteParameters routeParams = await solveRouteTask.CreateDefaultParametersAsync();

                // Make some changes to the default parameters
                routeParams.ReturnStops = true;
                routeParams.ReturnDirections = true;

                // Set the list of route stops that were defined at startup

                // Solve for the best route between the stops and store the result
                RouteResult solveRouteResult = await solveRouteTask.SolveRouteAsync(routeParams);

                // Get the first (should be only) route from the result
                Route firstRoute = solveRouteResult.Routes.First();

                // Get the route geometry (polyline)
                Polyline routePolyline = firstRoute.RouteGeometry;

                // Create a thick purple line symbol for the route
                SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Colors.Purple, 8.0);

                // Create a new graphic for the route geometry and add it to the graphics overlay
                Graphic routeGraphic = new Graphic(routePolyline, routeSymbol) { ZIndex = 0 };

                // Get a list of directions for the route and display it in the list box
                DirectionsListBox.ItemsSource = firstRoute.DirectionManeuvers.Select(direction => direction.DirectionText);
            catch (Exception ex)
                await Application.Current.MainPage.DisplayAlert("Error", ex.ToString(), "OK");

        private void ResetClick(object sender, EventArgs e)
            // Clear the list of directions
            DirectionsListBox.ItemsSource = null;

            // Remove the route graphic from the graphics overlay (only line graphic in the collection)
            int graphicsCount = _routeGraphicsOverlay.Graphics.Count;
            for (int i = graphicsCount; i > 0; i--)
                // Get this graphic and see if it has line geometry
                Graphic g = _routeGraphicsOverlay.Graphics[i - 1];
                if (g.Geometry.GeometryType == GeometryType.Polyline)
                    // Remove the graphic from the overlay

        private void ShowHideDirectionsList(object sender, EventArgs e)
            // Show the directions frame if it's hidden; hide if it's shown
            DirectionsFrame.IsVisible = !DirectionsFrame.IsVisible;
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=""
            <RowDefinition Height="Auto"/>
        <esriUI:MapView x:Name="MyMapView"/>
        <Frame x:Name="DirectionsFrame" 
               BackgroundColor="WhiteSmoke" Opacity=".85"
                HorizontalOptions="FillAndExpand" VerticalOptions="Start"
                Margin="5" Padding="5">
                <Label Text="Route directions:" 
                           Margin="0,0,0,2" />
                <ListView x:Name="DirectionsListBox"
        <StackLayout Grid.Row="1"
            <Button x:Name="SolveRouteButton"
                        Text="Solve Route"
            <Button x:Name="ResetButton"
            <Button x:Name="ShowHideDirectionsButton"
See Also
Additional Examples
Hyperlink to ExampleDescription
FindRouteDisplay directions for a route between two points.
MobileMapSearchAndRouteDisplay maps and use locators to enable search and routing offline using a Mobile Map Package.
NavigateRouteUse a routing service to navigate between points.
NavigateRouteReroutingNavigate between two points and dynamically recalculate an alternate route when the original route is unavailable.
OfflineRoutingSolve a route on-the-fly using offline data.
RouteAroundBarriersFind a route that reaches all stops without crossing any barriers.