Find route

View inWPFUWPFormsiOSAndroid
View on GitHub

Display directions for a route between two points.

Image of find route

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

  1. Create a RouteTask using a URL to an online route service.
  2. Generate default RouteParameters using routeTask.CreateDefaultParametersAsync().
  3. Set returnStops and returnDirections on the parameters to true.
  4. Add Stops to the parameters stops collection for each destination.
  5. Solve the route using routeTask.SolveAsync(routeParameters) to get a RouteResult.
  6. Iterate through the result's Routes. To display the route, create a graphic using the geometry from route.RouteGeometry. To display directions, use routeDirectionManeuvers, and for each DirectionManeuver, display DirectionManeuver.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

FindRoute.xamlFindRoute.xaml.cs
                                            
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
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage 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"
             xmlns:mapping="clr-namespace:Esri.ArcGISRuntime.Mapping;assembly=Esri.ArcGISRuntime"
             x:Class="ArcGISRuntime.Samples.FindRoute.FindRoute">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <esriUI:MapView x:Name="MyMapView"/>
        <Frame x:Name="DirectionsFrame"
               BackgroundColor="WhiteSmoke" Opacity=".85"
               IsVisible="False"
                HorizontalOptions="FillAndExpand" VerticalOptions="Start"
                Margin="5" Padding="5">
            <StackLayout>
                <Label Text="Route directions:"
                           Margin="0,0,0,2" />
                <ListView x:Name="DirectionsListBox"
                          VerticalOptions="FillAndExpand"
                         HeightRequest="300"/>
            </StackLayout>
        </Frame>
        <StackLayout Grid.Row="1"
                     Orientation="Horizontal"
                     HeightRequest="50"
                     Margin="5,10">
            <Button x:Name="SolveRouteButton"
                        HorizontalOptions="FillAndExpand"
                        Text="Solve Route"
                        Clicked="SolveRouteClick"/>
            <Button x:Name="ResetButton"
                        HorizontalOptions="FillAndExpand"
                        Text="Reset"
                        Clicked="ResetClick"/>
            <Button x:Name="ShowHideDirectionsButton"
                        HorizontalOptions="FillAndExpand"
                        Text="Directions"
                        Clicked="ShowHideDirectionsList"/>
        </StackLayout>
    </Grid>
</ContentPage>

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