View on GitHub Sample viewer app

Show your current position on the map, as well as switch between different types of auto pan modes.

Image of show device location

Use case

When using a map within a GIS, it may be helpful for a user to know their own location within a map, whether that’s to aid the user’s navigation or to provide an easy means of identifying/collecting geospatial information at their location.

How to use the sample

On the lower left, there is a switch that allows you to turn location tracking On and Off.

Tap the button in the lower right (which starts in Re-Center mode). A menu will appear with the following options:

  • Re-Center - Starts the location display with LocationDisplayAutoPanMode set to Recenter.
  • Navigation - Starts the location display with LocationDisplayAutoPanMode set to Navigation.
  • Compass - Starts the location display with LocationDisplayAutoPanMode set to CompassNavigation.

How it works

  1. Add the composable MapView to your UI.
  2. Get a LocationDisplay object by calling rememberLocationDisplay() and set it to the composable MapView.
  3. Use start() and stop() on the LocationDisplay.dataSource as necessary.

Relevant API

  • ArcGISMap
  • LocationDisplay
  • LocationDisplay.AutoPanMode
  • MapView

Additional information

Location permissions are required for this sample.

This sample demonstrates the following AutoPanMode options:

  • Recenter: In this mode, the MapView attempts to keep the location symbol on-screen by re-centering the location symbol when the symbol moves outside a “wander extent”. The location symbol may move freely within the wander extent, but as soon as the symbol exits the wander extent, the MapView re-centers the map on the symbol.

  • Navigation: This mode is best suited for in-vehicle navigation.

  • CompassNavigation: This mode is better suited for waypoint navigation when the user is walking.

This sample uses the GeoView-Compose Toolkit module to be able to implement a composable MapView.

Tags

compass, geoview-compose, GPS, location, map, mobile, navigation, toolkit

Sample Code

MainActivity.kt MainActivity.kt ShowDeviceLocationViewModel.kt ShowDeviceLocationScreen.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.showdevicelocation
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import com.arcgismaps.ApiKey
import com.arcgismaps.ArcGISEnvironment
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
import com.esri.arcgismaps.sample.showdevicelocation.screens.ShowDeviceLocationScreen
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// authentication with an API key or named user is
// required to access basemaps and other location services
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.ACCESS_TOKEN)
enableEdgeToEdge()
setContent {
SampleAppTheme {
ShowDeviceLocationApp()
}
}
}
@Composable
private fun ShowDeviceLocationApp() {
Surface(color = MaterialTheme.colorScheme.background) {
ShowDeviceLocationScreen(
sampleName = getString(R.string.show_device_location_app_name)
)
}
}
}