View on GitHub Sample viewer app

Use a route displayed in the real world to navigate.

Image of augment reality to navigate route

Use case

It can be hard to navigate using 2D maps in unfamiliar environments. You can use full-scale AR to show a route overlaid on the real-world for easier navigation.

How to use the sample

The app opens with a map centered on your current location. Tap the map or use your current location to set a start point and a destination. The route will be calculated and displayed as a line. Tap the “Navigate in augmented reality” button. Follow the route displayed in the AR view. Directions will be provided as you progress.

How it works

  1. The map page is used to plan the route before starting navigation in augmented reality. See the Find route sample for a more focused demonstration of that workflow.
  2. Pass the resulting Route to the augmented reality view model used to augment reality with navigation information.
  3. Add a WorldScaleSceneView composable to the augmented reality screen, available in the ArcGIS Maps SDK for Kotlin toolkit.
    • The component is available both in World tracking and Geospatial tracking modes. Geospatial tracking uses street view data to calibrate augmented reality positioning and is available with an ARCORE API key.
  4. Get a list of DirectionManeuvers from the Route (solved in 2D) and add z values to the route’s geometry using Esri’s ElevationSource.fromTerrain3dService().
  5. Using heading and pitch information calculated from one point to the next, create a ModelSceneSymbol Graphic oriented towards then next point.
    • Arrows that represent a turn are also given a roll of 90 to stand upright and animated for greater visibility.
  6. Create a RouteTracker to track the user’s location and provide navigation instructions.
  7. On location updates from the RouteTracker, determine the closest arrow Graphic to the user’s location and change the graphic’s behind the user to be partly opaque.
  8. A UI slider adjusts the number of the arrow Graphics drawn ahead of the user. Too many graphics can clutter the UI and be confusing when shown behind real world objects.
  9. A calibration view is provided by the WorldScaleSceneView to adjust the heading of the camera when in World tracking mode.

Relevant API

  • LocationDataSource
  • ModelSceneSymbol
  • RouteResult
  • RouteTask
  • RouteTracker
  • Surface
  • WorldScaleSceneView

About the data

This sample uses Esri’s world elevation service to ensure that route lines are placed appropriately in 3D space. It uses Esri’s world routing service to calculate routes. The world routing service requires an API key and does consume ArcGIS Online credits.

Additional information

This sample requires a device that is compatible with ARCore.

Unlike other scene samples, there’s no need for a basemap while navigating, because context is provided by the camera feed showing the real environment. The base surface’s opacity is set to zero to prevent it from interfering with the AR experience.

This sample uses the WorldScaleSceneView toolkit component. For information about setting up the toolkit, as well as code for the underlying component, visit the toolkit docs.

Note that apps using ARCore must comply with ARCore’s user privacy requirements. See this page for more information.

Tags

augmented reality, directions, full-scale, guidance, mixed reality, navigate, navigation, real-scale, route, routing, world-scale

Sample Code

DownloadActivity.kt DownloadActivity.kt MainActivity.kt AugmentedRealityViewModel.kt RouteViewModel.kt SharedRepository.kt AugmentRealityToNavigateRouteNavGraph.kt AugmentedRealityScreen.kt RouteScreen.kt
/* Copyright 2025 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*
*/
package com.esri.arcgismaps.sample.augmentrealitytonavigateroute
import android.content.Intent
import android.os.Bundle
import com.esri.arcgismaps.sample.sampleslib.DownloaderActivity
class DownloadActivity : DownloaderActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
downloadAndStartSample(
Intent(this, MainActivity::class.java),
// get the app name of the sample
getString(R.string.augment_reality_to_navigate_route_app_name),
// ArcGIS Portal item containing the arrow graphic
listOf(
"https://arcgisruntime.maps.arcgis.com/home/item.html?id=248ea5112c8a46ee97fe3b8603d1e1dd"
)
)
}
}