Navigate route

View inMAUIUWPWPFWinUIView on GitHub

Use a routing service to navigate between points.

Image of navigate route

Use case

Navigation is often used by field workers while traveling between points to get live directions based on their location.

How to use the sample

Click 'Navigate' to simulate traveling and to receive directions from a preset starting point to a preset destination. Click 'Recenter' to refocus on the location display.

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 for each destination using SetStops(stops).
  5. Solve the route using RouteTask.SolveRouteAsync(routeParameters) to get a RouteResult.
  6. Create a RouteTracker using the route result, and the index of the desired route to take.
  7. Use TrackLocationAsync(LocationDataSource.Location) to track the location of the device and update the route tracking status.
  8. Add a listener to capture TrackingStatusChangedEvents, and then get the TrackingStatus and use it to display updated route information. Tracking status includes a variety of information on the route progress, such as the remaining distance, remaining geometry or traversed geometry (represented by a Polyline), or the remaining time (TimeSpan), amongst others.
  9. Add a NewVoiceGuidanceListener to get the VoiceGuidance whenever new instructions are available. From the voice guidance, get the string representing the directions and use a text-to-speech engine to output the maneuver directions.
  10. You can also query the tracking status for the current DirectionManeuver index, retrieve that maneuver from the Route and get it's direction text to display in the GUI.
  11. To establish whether the destination has been reached, get the DestinationStatus from the tracking status. If the destination status is Reached, we have arrived at the destination and can stop routing. If there are several destinations in your route, and the remaining destination count is greater than 1, switch the route tracker to the next destination.

Relevant API

  • DestinationStatus
  • DirectionManeuver
  • Location
  • LocationDataSource
  • ReroutingStrategy
  • Route
  • RouteParameters
  • RouteTask
  • RouteTracker
  • Stop
  • VoiceGuidance

About the data

The route taken in this sample goes from the San Diego Convention Center, site of the annual Esri User Conference, to the Fleet Science Center, San Diego.

Tags

directions, maneuver, navigation, route, turn-by-turn, voice

Sample Code

NavigateRoute.xamlNavigateRoute.xamlNavigateRoute.xaml.cs
Use dark colors for code blocksCopy
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
45
46
47
48
<UserControl
    x:Class="ArcGIS.UWP.Samples.NavigateRoute.NavigateRoute"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
    <Grid>
        <esriUI:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="100" />
                </Grid.RowDefinitions>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Button
                        x:Name="StartNavigationButton"
                        Grid.Column="0"
                        Margin="5"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Center"
                        Click="StartNavigation"
                        Content="Navigate route"
                        IsEnabled="False" />
                    <Button
                        x:Name="RecenterButton"
                        Grid.Column="1"
                        Margin="5"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Center"
                        Click="RecenterButton_Click"
                        Content="Recenter"
                        IsEnabled="False" />
                </Grid>
                <TextBlock
                    x:Name="MessagesTextBlock"
                    Grid.Row="3"
                    Margin="5"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch"
                    TextWrapping="Wrap" />
            </Grid>
        </Border>
    </Grid>
</UserControl>

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