Display directions for a route between two points.
Use case
Find routes with driving directions between any number of locations. You might use the ArcGIS platform to create a custom network for routing on a private roads.
How to use the sample
For simplicity, the sample comes loaded with a start and end stop. You can tap on the Find Route button to display a route between these stops. Once the route is generated, turn-by-turn directions are shown in a list.
How it works
- Create a
RouteTask
using a URL to an online route service. - Generate default
RouteParameters
usingrouteTask.CreateDefaultParametersAsync()
. - Set
returnStops
andreturnDirections
on the parameters to true. - Add
Stop
s to the parametersstops
collection for each destination. - Solve the route using
routeTask.SolveAsync(routeParameters)
to get aRouteResult
. - Iterate through the result's
Route
s. To display the route, create a graphic using the geometry fromroute.RouteGeometry
. To display directions, userouteDirectionManeuvers
, and for eachDirectionManeuver
, displayDirectionManeuver.DirectionText
.
Relevant API
- DirectionManeuver
- Route
- RouteParameters
- RouteResult
- RouteTask
- Stop
Tags
directions, driving, navigation, network, network analysis, route, routing, shortest path, turn-by-turn
Sample Code
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGISRuntime.Samples.FindRoute.FindRoute"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<esriUI:MapView x:Name="MyMapView" />
<Frame x:Name="DirectionsFrame"
Margin="5"
Padding="5"
BackgroundColor="WhiteSmoke"
HorizontalOptions="FillAndExpand"
IsVisible="False"
Opacity=".85"
VerticalOptions="Start">
<StackLayout>
<Label Margin="0,0,0,2" Text="Route directions:" />
<ListView x:Name="DirectionsListBox"
HeightRequest="300"
VerticalOptions="FillAndExpand" />
</StackLayout>
</Frame>
<StackLayout Grid.Row="1"
Margin="5,10"
HeightRequest="50"
Orientation="Horizontal">
<Button x:Name="SolveRouteButton"
Clicked="SolveRouteClick"
HorizontalOptions="FillAndExpand"
Text="Solve Route" />
<Button x:Name="ResetButton"
Clicked="ResetClick"
HorizontalOptions="FillAndExpand"
Text="Reset" />
<Button x:Name="ShowHideDirectionsButton"
Clicked="ShowHideDirectionsList"
HorizontalOptions="FillAndExpand"
Text="Directions" />
</StackLayout>
</Grid>
</ContentPage>