Use a routing service to navigate between two points.

Use case
Navigation is often used by field workers while traveling between two points to get live directions based on their location.
How to use the sample
Tap “Navigate” to simulate traveling and to receive directions from a preset starting point to a preset destination. Tap “Reset” to start the simulation from the beginning.
How it works
- Create an
RouteTaskusing a URL to an online route service. - Generate default
RouteParametersusingRouteTask.makeDefaultParameters(). - Set
returnsRoutes,returnsStops, andreturnsDirectionson the parameters totrue. - Assign all
Stopobjects to the route parameters usingRouteParameters.setStops(_:). - Solve the route using
RouteTask.solveRoute(using:)to get aRouteResult. - Create an
RouteTrackerusing the route result, and the index of the desired route to take. - Create a
RouteTrackerLocationDataSourcewith the route tracker and aSimulatedLocationDataSourceobject to snap the location display to the route. - Use
RouteTracker.trackingStatusto be notified ofTrackingStatuschanges, and use them to display updated route information.TrackingStatusincludes a variety of information on the route progress, such as the remaining distance, remaining geometry or traversed geometry (represented by anPolyline), or the remaining time (TimeInterval), amongst others. - Use
RouteTracker.voiceGuidancesto be notified of new voice guidances. From the voice guidance, get theVoiceGuidance.textrepresenting the directions and use a text-to-speech engine to output the maneuver directions. - You can also query the tracking status for the current
DirectionManeuverindex, retrieve that maneuver from theRoute, and get its direction text to display in the GUI. - To establish whether the destination has been reached, get the
destinationStatusfrom the tracking status. If the destination status isreachedand theremainingDestinationCountis 1, you have arrived at the destination and can stop routing. If there are several destinations on 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
- Route
- RouteParameters
- RouteTask
- RouteTracker
- RouteTrackerLocationDataSource
- SimulatedLocationDataSource
- 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