Learn how to display point, line, and polygon graphics A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more in a map A map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more .

add a point line and polygon

You typically use graphics A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more to display geographic data that is not connected to a database and that is not persisted, like highlighting a route between two locations, displaying a search buffer around a selected point, or showing the location of map coordinates entered by the user. Graphics are composed of a geometry A geometry is a geometric shape, such as a point, polyline, or polygon, that contains one or more coordinates and a spatial reference. Learn more , symbol A symbol defines the properties used to display a geometry or text. Learn more , and attributes Attributes are fields and values for a single feature or non-spatial record. They are typically stored in a database or service such as a feature service. Learn more .

In this tutorial, you display points, lines, and polygons on a map as graphics A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more .

Prerequisites

Before starting this tutorial, you need the following:

  1. An ArcGIS Location Platform or ArcGIS Online account.

  2. A development and deployment environment that meets the system requirements.

  3. An IDE for Android development in Kotlin.

Develop or download

You have two options for completing this tutorial:

  1. Option 1: Develop the code or
  2. Option 2: Download the completed solution

Option 1: Develop the code

Open an Android Studio project

  1. Open the project you created by completing the Display a map tutorial.

  2. Continue with the following instructions to display a point, line, and polygon in the map.

  3. Modify the old project for use in this new tutorial.

Add import statements

  1. In the Android view, open app > kotlin+java > com.example.app > screens > MainScreen.kt. Replace the import statements with the imports needed for this tutorial.

    MainScreen.kt
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R

Add a graphics overlay and a list of graphics overlay

You will create a GraphicsOverlay. Then add the graphics overlay to a list named graphicsOverlays.

In subsequent sections of this tutorial, you will create a point, a line, and a polygon and add each of them to the GraphicsOverlay.

  1. In the MainScreen composable, add a remember block and create a GraphicsOverlay inside it. Then assign remember to a local variable named graphicsOverlay.

    MainScreen.kt
    33 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    )
    }
    12 collapsed lines
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }
  2. Add a remember block. Inside it, create a list that contains the graphicsOverlay you just created. Then assign remember to a local variable named graphicsOverlays.

    MainScreen.kt
    33 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    // Create a list of graphics overlays used by the MapView
    val graphicsOverlays = remember { listOf(graphicsOverlay) }
    22 collapsed lines
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    )
    }
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }
  3. Pass graphicsOverlays as the graphicsOverlays argument to MapView.

    MainScreen.kt
    46 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    // Create a list of graphics overlays used by the MapView
    val graphicsOverlays = remember { listOf(graphicsOverlay) }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    graphicsOverlays = graphicsOverlays
    )
    }
    12 collapsed lines
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }

Add a point graphic

A point graphic A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more is created using a point A geometry is a geometric shape, such as a point, polyline, or polygon, that contains one or more coordinates and a spatial reference. Learn more and a marker symbol A symbol defines the properties used to display a geometry or text. Learn more . A point is defined with x and y coordinates, and a spatial reference A spatial reference is a set of parameters, typically defined by a WKID, that define the coordinate system and spatial properties for geographic data. Applications use a spatial reference to correctly display the position of geographic data in a map or scene. Learn more . For latitude and longitude coordinates, the spatial reference is WGS84.

  1. Create a lazy top-level property named blueOutlineSymbol. In the lazy block, create a solid, blue, 2px-wide SimpleLineSymbol.

    MainScreen.kt
    33 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    // Create a blue outline symbol.
    private val blueOutlineSymbol by lazy {
    SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(0, 0, 255), 2f)
    }
    37 collapsed lines
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    // Create a list of graphics overlays used by the MapView
    val graphicsOverlays = remember { listOf(graphicsOverlay) }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    graphicsOverlays = graphicsOverlays
    )
    }
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }
  2. Create a lazy top-level property named pointGraphic.

    MainScreen.kt
    33 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    private val pointGraphic by lazy {
    }
    37 collapsed lines
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    // Create a list of graphics overlays used by the MapView
    val graphicsOverlays = remember { listOf(graphicsOverlay) }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    graphicsOverlays = graphicsOverlays
    )
    }
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }
  3. In the lazy block of thepointGraphic property , create a Point and a SimpleMarkerSymbol. To create the point, provide x (longitude) and y (latitude) coordinates and a SpatialReference (by calling wgs84() on SpatialReference).

    Assign blueOutlineSymbol to the outline property of simpleMarkerSymbol.

    MainScreen.kt
    38 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    // Create a blue outline symbol.
    private val blueOutlineSymbol by lazy {
    SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(0, 0, 255), 2f)
    }
    private val pointGraphic by lazy {
    // Create a point geometry with a location and spatial reference.
    // Point(latitude, longitude, spatial reference)
    val point = Point(
    x = -118.8065,
    y = 34.0005,
    spatialReference = SpatialReference.wgs84()
    )
    // Create a point symbol that is an small red circle and assign the blue outline symbol to its outline property.
    val simpleMarkerSymbol = SimpleMarkerSymbol(
    style = SimpleMarkerSymbolStyle.Circle,
    color = Color.red,
    size = 10f
    )
    simpleMarkerSymbol.outline = blueOutlineSymbol
    }
    37 collapsed lines
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    // Create a list of graphics overlays used by the MapView
    val graphicsOverlays = remember { listOf(graphicsOverlay) }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    graphicsOverlays = graphicsOverlays
    )
    }
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }
  4. Create a Graphic with point and simpleMarkerSymbol.

    MainScreen.kt
    38 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    // Create a blue outline symbol.
    private val blueOutlineSymbol by lazy {
    SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(0, 0, 255), 2f)
    }
    private val pointGraphic by lazy {
    // Create a point geometry with a location and spatial reference.
    // Point(latitude, longitude, spatial reference)
    val point = Point(
    x = -118.8065,
    y = 34.0005,
    spatialReference = SpatialReference.wgs84()
    )
    // Create a point symbol that is an small red circle and assign the blue outline symbol to its outline property.
    val simpleMarkerSymbol = SimpleMarkerSymbol(
    style = SimpleMarkerSymbolStyle.Circle,
    color = Color.red,
    size = 10f
    )
    simpleMarkerSymbol.outline = blueOutlineSymbol
    // Create a graphic with the point geometry and symbol.
    Graphic(
    geometry = point,
    symbol = simpleMarkerSymbol
    )
    }
    37 collapsed lines
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    // Create a list of graphics overlays used by the MapView
    val graphicsOverlays = remember { listOf(graphicsOverlay) }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    graphicsOverlays = graphicsOverlays
    )
    }
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }
  5. In MainScreen, display the graphic by adding it to the graphics property of graphicsOverlay.

    MainScreen.kt
    64 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    // Create a blue outline symbol.
    private val blueOutlineSymbol by lazy {
    SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(0, 0, 255), 2f)
    }
    private val pointGraphic by lazy {
    // Create a point geometry with a location and spatial reference.
    // Point(latitude, longitude, spatial reference)
    val point = Point(
    x = -118.8065,
    y = 34.0005,
    spatialReference = SpatialReference.wgs84()
    )
    // Create a point symbol that is an small red circle and assign the blue outline symbol to its outline property.
    val simpleMarkerSymbol = SimpleMarkerSymbol(
    style = SimpleMarkerSymbolStyle.Circle,
    color = Color.red,
    size = 10f
    )
    simpleMarkerSymbol.outline = blueOutlineSymbol
    // Create a graphic with the point geometry and symbol.
    Graphic(
    geometry = point,
    symbol = simpleMarkerSymbol
    )
    }
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    // Add the point graphic to the graphics overlay.
    graphicsOverlay.graphics.add(pointGraphic)
    // Create a list of graphics overlays used by the MapView
    val graphicsOverlays = remember { listOf(graphicsOverlay) }
    24 collapsed lines
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    graphicsOverlays = graphicsOverlays
    )
    }
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }

Click Run > Run > app to run the app.

You should see a point graphic in Point Dume State Beach.

Add a line graphic

A line graphic A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more is created using a polyline A geometry is a geometric shape, such as a point, polyline, or polygon, that contains one or more coordinates and a spatial reference. Learn more and a line symbol A symbol defines the properties used to display a geometry or text. Learn more . A polyline is defined as a sequence of points.

  1. Create a lazy top-level property named polylineGraphic.

    MainScreen.kt
    64 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    // Create a blue outline symbol.
    private val blueOutlineSymbol by lazy {
    SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(0, 0, 255), 2f)
    }
    private val pointGraphic by lazy {
    // Create a point geometry with a location and spatial reference.
    // Point(latitude, longitude, spatial reference)
    val point = Point(
    x = -118.8065,
    y = 34.0005,
    spatialReference = SpatialReference.wgs84()
    )
    // Create a point symbol that is an small red circle and assign the blue outline symbol to its outline property.
    val simpleMarkerSymbol = SimpleMarkerSymbol(
    style = SimpleMarkerSymbolStyle.Circle,
    color = Color.red,
    size = 10f
    )
    simpleMarkerSymbol.outline = blueOutlineSymbol
    // Create a graphic with the point geometry and symbol.
    Graphic(
    geometry = point,
    symbol = simpleMarkerSymbol
    )
    }
    private val polylineGraphic by lazy {
    }
    40 collapsed lines
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    // Add the point graphic to the graphics overlay.
    graphicsOverlay.graphics.add(pointGraphic)
    // Create a list of graphics overlays used by the MapView
    val graphicsOverlays = remember { listOf(graphicsOverlay) }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    graphicsOverlays = graphicsOverlays
    )
    }
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }
  2. In the lazy block, create a Polyline and a SimpleLineSymbol. To create the polyline, create a PolylineBuilder and then call toGeometry() on the polygon builder.

    MainScreen.kt
    64 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    // Create a blue outline symbol.
    private val blueOutlineSymbol by lazy {
    SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(0, 0, 255), 2f)
    }
    private val pointGraphic by lazy {
    // Create a point geometry with a location and spatial reference.
    // Point(latitude, longitude, spatial reference)
    val point = Point(
    x = -118.8065,
    y = 34.0005,
    spatialReference = SpatialReference.wgs84()
    )
    // Create a point symbol that is an small red circle and assign the blue outline symbol to its outline property.
    val simpleMarkerSymbol = SimpleMarkerSymbol(
    style = SimpleMarkerSymbolStyle.Circle,
    color = Color.red,
    size = 10f
    )
    simpleMarkerSymbol.outline = blueOutlineSymbol
    // Create a graphic with the point geometry and symbol.
    Graphic(
    geometry = point,
    symbol = simpleMarkerSymbol
    )
    }
    private val polylineGraphic by lazy {
    // Create a blue line symbol for the polyline.
    val polylineSymbol = SimpleLineSymbol(
    style = SimpleLineSymbolStyle.Solid,
    color = Color.fromRgba(0, 0, 255),
    width = 3f
    )
    // Create a polylineBuilder with a spatial reference and add three points to it.
    val polylineBuilder = PolylineBuilder(SpatialReference.wgs84()) {
    addPoint(-118.8215, 34.0139)
    addPoint(-118.8148, 34.0080)
    addPoint(-118.8088, 34.0016)
    }
    // then get the polyline from the polyline builder
    val polyline = polylineBuilder.toGeometry()
    }
    40 collapsed lines
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    // Add the point graphic to the graphics overlay.
    graphicsOverlay.graphics.add(pointGraphic)
    // Create a list of graphics overlays used by the MapView
    val graphicsOverlays = remember { listOf(graphicsOverlay) }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    graphicsOverlays = graphicsOverlays
    )
    }
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }
  3. Create a Graphic with polyline and polylineSymbol.

    MainScreen.kt
    64 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    // Create a blue outline symbol.
    private val blueOutlineSymbol by lazy {
    SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(0, 0, 255), 2f)
    }
    private val pointGraphic by lazy {
    // Create a point geometry with a location and spatial reference.
    // Point(latitude, longitude, spatial reference)
    val point = Point(
    x = -118.8065,
    y = 34.0005,
    spatialReference = SpatialReference.wgs84()
    )
    // Create a point symbol that is an small red circle and assign the blue outline symbol to its outline property.
    val simpleMarkerSymbol = SimpleMarkerSymbol(
    style = SimpleMarkerSymbolStyle.Circle,
    color = Color.red,
    size = 10f
    )
    simpleMarkerSymbol.outline = blueOutlineSymbol
    // Create a graphic with the point geometry and symbol.
    Graphic(
    geometry = point,
    symbol = simpleMarkerSymbol
    )
    }
    private val polylineGraphic by lazy {
    // Create a blue line symbol for the polyline.
    val polylineSymbol = SimpleLineSymbol(
    style = SimpleLineSymbolStyle.Solid,
    color = Color.fromRgba(0, 0, 255),
    width = 3f
    )
    // Create a polylineBuilder with a spatial reference and add three points to it.
    val polylineBuilder = PolylineBuilder(SpatialReference.wgs84()) {
    addPoint(-118.8215, 34.0139)
    addPoint(-118.8148, 34.0080)
    addPoint(-118.8088, 34.0016)
    }
    // then get the polyline from the polyline builder
    val polyline = polylineBuilder.toGeometry()
    // Create a polyline graphic with the polyline geometry and symbol.
    Graphic(
    geometry = polyline,
    symbol = polylineSymbol
    )
    }
    40 collapsed lines
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    // Add the point graphic to the graphics overlay.
    graphicsOverlay.graphics.add(pointGraphic)
    // Create a list of graphics overlays used by the MapView
    val graphicsOverlays = remember { listOf(graphicsOverlay) }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    graphicsOverlays = graphicsOverlays
    )
    }
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }
  4. In MainScreen, display the graphic by adding it to the graphics property of graphicsOverlay.

    MainScreen.kt
    90 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    // Create a blue outline symbol.
    private val blueOutlineSymbol by lazy {
    SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(0, 0, 255), 2f)
    }
    private val pointGraphic by lazy {
    // Create a point geometry with a location and spatial reference.
    // Point(latitude, longitude, spatial reference)
    val point = Point(
    x = -118.8065,
    y = 34.0005,
    spatialReference = SpatialReference.wgs84()
    )
    // Create a point symbol that is an small red circle and assign the blue outline symbol to its outline property.
    val simpleMarkerSymbol = SimpleMarkerSymbol(
    style = SimpleMarkerSymbolStyle.Circle,
    color = Color.red,
    size = 10f
    )
    simpleMarkerSymbol.outline = blueOutlineSymbol
    // Create a graphic with the point geometry and symbol.
    Graphic(
    geometry = point,
    symbol = simpleMarkerSymbol
    )
    }
    private val polylineGraphic by lazy {
    // Create a blue line symbol for the polyline.
    val polylineSymbol = SimpleLineSymbol(
    style = SimpleLineSymbolStyle.Solid,
    color = Color.fromRgba(0, 0, 255),
    width = 3f
    )
    // Create a polylineBuilder with a spatial reference and add three points to it.
    val polylineBuilder = PolylineBuilder(SpatialReference.wgs84()) {
    addPoint(-118.8215, 34.0139)
    addPoint(-118.8148, 34.0080)
    addPoint(-118.8088, 34.0016)
    }
    // then get the polyline from the polyline builder
    val polyline = polylineBuilder.toGeometry()
    // Create a polyline graphic with the polyline geometry and symbol.
    Graphic(
    geometry = polyline,
    symbol = polylineSymbol
    )
    }
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    // Add the point graphic to the graphics overlay.
    graphicsOverlay.graphics.add(pointGraphic)
    // Add the polyline graphic to the graphics overlay.
    graphicsOverlay.graphics.add(polylineGraphic)
    // Create a list of graphics overlays used by the MapView
    val graphicsOverlays = remember { listOf(graphicsOverlay) }
    24 collapsed lines
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    graphicsOverlays = graphicsOverlays
    )
    }
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }

Click Run > Run > app to run the app.

You should see a point and line graphic along Westward Beach.

Add a polygon graphic

A polygon graphic A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more is created using a polygon A geometry is a geometric shape, such as a point, polyline, or polygon, that contains one or more coordinates and a spatial reference. Learn more and a fill symbol A symbol defines the properties used to display a geometry or text. Learn more . A polygon is defined as a sequence of points that describe a closed boundary.

  1. Create a lazy top-level property named polygonGraphic.

    MainScreen.kt
    90 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    // Create a blue outline symbol.
    private val blueOutlineSymbol by lazy {
    SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(0, 0, 255), 2f)
    }
    private val pointGraphic by lazy {
    // Create a point geometry with a location and spatial reference.
    // Point(latitude, longitude, spatial reference)
    val point = Point(
    x = -118.8065,
    y = 34.0005,
    spatialReference = SpatialReference.wgs84()
    )
    // Create a point symbol that is an small red circle and assign the blue outline symbol to its outline property.
    val simpleMarkerSymbol = SimpleMarkerSymbol(
    style = SimpleMarkerSymbolStyle.Circle,
    color = Color.red,
    size = 10f
    )
    simpleMarkerSymbol.outline = blueOutlineSymbol
    // Create a graphic with the point geometry and symbol.
    Graphic(
    geometry = point,
    symbol = simpleMarkerSymbol
    )
    }
    private val polylineGraphic by lazy {
    // Create a blue line symbol for the polyline.
    val polylineSymbol = SimpleLineSymbol(
    style = SimpleLineSymbolStyle.Solid,
    color = Color.fromRgba(0, 0, 255),
    width = 3f
    )
    // Create a polylineBuilder with a spatial reference and add three points to it.
    val polylineBuilder = PolylineBuilder(SpatialReference.wgs84()) {
    addPoint(-118.8215, 34.0139)
    addPoint(-118.8148, 34.0080)
    addPoint(-118.8088, 34.0016)
    }
    // then get the polyline from the polyline builder
    val polyline = polylineBuilder.toGeometry()
    // Create a polyline graphic with the polyline geometry and symbol.
    Graphic(
    geometry = polyline,
    symbol = polylineSymbol
    )
    }
    private val polygonGraphic by lazy {
    }
    43 collapsed lines
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    // Add the point graphic to the graphics overlay.
    graphicsOverlay.graphics.add(pointGraphic)
    // Add the polyline graphic to the graphics overlay.
    graphicsOverlay.graphics.add(polylineGraphic)
    // Create a list of graphics overlays used by the MapView
    val graphicsOverlays = remember { listOf(graphicsOverlay) }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    graphicsOverlays = graphicsOverlays
    )
    }
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }
  2. In the lazy block, create a Polygon and a SimpleFillSymbol. To create the polygon, create a PolygonBuilder and then call toGeometry() on the polygon builder.

    Next, create a SimpleFillSymbol that has a solid red fill with an alpha channel of 128 and uses the blueOutlineSymbol defined earlier.

    MainScreen.kt
    90 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    // Create a blue outline symbol.
    private val blueOutlineSymbol by lazy {
    SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(0, 0, 255), 2f)
    }
    private val pointGraphic by lazy {
    // Create a point geometry with a location and spatial reference.
    // Point(latitude, longitude, spatial reference)
    val point = Point(
    x = -118.8065,
    y = 34.0005,
    spatialReference = SpatialReference.wgs84()
    )
    // Create a point symbol that is an small red circle and assign the blue outline symbol to its outline property.
    val simpleMarkerSymbol = SimpleMarkerSymbol(
    style = SimpleMarkerSymbolStyle.Circle,
    color = Color.red,
    size = 10f
    )
    simpleMarkerSymbol.outline = blueOutlineSymbol
    // Create a graphic with the point geometry and symbol.
    Graphic(
    geometry = point,
    symbol = simpleMarkerSymbol
    )
    }
    private val polylineGraphic by lazy {
    // Create a blue line symbol for the polyline.
    val polylineSymbol = SimpleLineSymbol(
    style = SimpleLineSymbolStyle.Solid,
    color = Color.fromRgba(0, 0, 255),
    width = 3f
    )
    // Create a polylineBuilder with a spatial reference and add three points to it.
    val polylineBuilder = PolylineBuilder(SpatialReference.wgs84()) {
    addPoint(-118.8215, 34.0139)
    addPoint(-118.8148, 34.0080)
    addPoint(-118.8088, 34.0016)
    }
    // then get the polyline from the polyline builder
    val polyline = polylineBuilder.toGeometry()
    // Create a polyline graphic with the polyline geometry and symbol.
    Graphic(
    geometry = polyline,
    symbol = polylineSymbol
    )
    }
    private val polygonGraphic by lazy {
    // Create a polygon builder with a spatial reference and add five vertices (points) to it.
    // Then get the polygon from the polygon builder.
    val polygonBuilder = PolygonBuilder(SpatialReference.wgs84()) {
    addPoint(-118.8189, 34.0137)
    addPoint(-118.8067, 34.0215)
    addPoint(-118.7914, 34.0163)
    addPoint(-118.7959, 34.0085)
    addPoint(-118.8085, 34.0035)
    }
    val polygon = polygonBuilder.toGeometry()
    // Create a red fill symbol with an alpha component of 128: values can run from 0 to 255).
    val polygonFillSymbol = SimpleFillSymbol(
    style = SimpleFillSymbolStyle.Solid,
    color = Color.fromRgba(255, 0, 0, 128),
    outline = blueOutlineSymbol
    )
    }
    43 collapsed lines
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    // Add the point graphic to the graphics overlay.
    graphicsOverlay.graphics.add(pointGraphic)
    // Add the polyline graphic to the graphics overlay.
    graphicsOverlay.graphics.add(polylineGraphic)
    // Create a list of graphics overlays used by the MapView
    val graphicsOverlays = remember { listOf(graphicsOverlay) }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    graphicsOverlays = graphicsOverlays
    )
    }
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }
  3. Create a Graphic with polygon and polygonFillSymbol.

    MainScreen.kt
    90 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    // Create a blue outline symbol.
    private val blueOutlineSymbol by lazy {
    SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(0, 0, 255), 2f)
    }
    private val pointGraphic by lazy {
    // Create a point geometry with a location and spatial reference.
    // Point(latitude, longitude, spatial reference)
    val point = Point(
    x = -118.8065,
    y = 34.0005,
    spatialReference = SpatialReference.wgs84()
    )
    // Create a point symbol that is an small red circle and assign the blue outline symbol to its outline property.
    val simpleMarkerSymbol = SimpleMarkerSymbol(
    style = SimpleMarkerSymbolStyle.Circle,
    color = Color.red,
    size = 10f
    )
    simpleMarkerSymbol.outline = blueOutlineSymbol
    // Create a graphic with the point geometry and symbol.
    Graphic(
    geometry = point,
    symbol = simpleMarkerSymbol
    )
    }
    private val polylineGraphic by lazy {
    // Create a blue line symbol for the polyline.
    val polylineSymbol = SimpleLineSymbol(
    style = SimpleLineSymbolStyle.Solid,
    color = Color.fromRgba(0, 0, 255),
    width = 3f
    )
    // Create a polylineBuilder with a spatial reference and add three points to it.
    val polylineBuilder = PolylineBuilder(SpatialReference.wgs84()) {
    addPoint(-118.8215, 34.0139)
    addPoint(-118.8148, 34.0080)
    addPoint(-118.8088, 34.0016)
    }
    // then get the polyline from the polyline builder
    val polyline = polylineBuilder.toGeometry()
    // Create a polyline graphic with the polyline geometry and symbol.
    Graphic(
    geometry = polyline,
    symbol = polylineSymbol
    )
    }
    private val polygonGraphic by lazy {
    // Create a polygon builder with a spatial reference and add five vertices (points) to it.
    // Then get the polygon from the polygon builder.
    val polygonBuilder = PolygonBuilder(SpatialReference.wgs84()) {
    addPoint(-118.8189, 34.0137)
    addPoint(-118.8067, 34.0215)
    addPoint(-118.7914, 34.0163)
    addPoint(-118.7959, 34.0085)
    addPoint(-118.8085, 34.0035)
    }
    val polygon = polygonBuilder.toGeometry()
    // Create a red fill symbol with an alpha component of 128: values can run from 0 to 255).
    val polygonFillSymbol = SimpleFillSymbol(
    style = SimpleFillSymbolStyle.Solid,
    color = Color.fromRgba(255, 0, 0, 128),
    outline = blueOutlineSymbol
    )
    // Create a polygon graphic from the polygon geometry and symbol.
    Graphic(
    geometry = polygon,
    symbol = polygonFillSymbol
    )
    }
    43 collapsed lines
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    // Add the point graphic to the graphics overlay.
    graphicsOverlay.graphics.add(pointGraphic)
    // Add the polyline graphic to the graphics overlay.
    graphicsOverlay.graphics.add(polylineGraphic)
    // Create a list of graphics overlays used by the MapView
    val graphicsOverlays = remember { listOf(graphicsOverlay) }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    graphicsOverlays = graphicsOverlays
    )
    }
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }
  4. In MainScreen, display the graphic by adding it to the graphics property of graphicsOverlay.

    MainScreen.kt
    118 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.geometry.Point
    import com.arcgismaps.geometry.PolygonBuilder
    import com.arcgismaps.geometry.PolylineBuilder
    import com.arcgismaps.geometry.SpatialReference
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
    import com.arcgismaps.mapping.view.Graphic
    import com.arcgismaps.mapping.view.GraphicsOverlay
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    // Create a blue outline symbol.
    private val blueOutlineSymbol by lazy {
    SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(0, 0, 255), 2f)
    }
    private val pointGraphic by lazy {
    // Create a point geometry with a location and spatial reference.
    // Point(latitude, longitude, spatial reference)
    val point = Point(
    x = -118.8065,
    y = 34.0005,
    spatialReference = SpatialReference.wgs84()
    )
    // Create a point symbol that is an small red circle and assign the blue outline symbol to its outline property.
    val simpleMarkerSymbol = SimpleMarkerSymbol(
    style = SimpleMarkerSymbolStyle.Circle,
    color = Color.red,
    size = 10f
    )
    simpleMarkerSymbol.outline = blueOutlineSymbol
    // Create a graphic with the point geometry and symbol.
    Graphic(
    geometry = point,
    symbol = simpleMarkerSymbol
    )
    }
    private val polylineGraphic by lazy {
    // Create a blue line symbol for the polyline.
    val polylineSymbol = SimpleLineSymbol(
    style = SimpleLineSymbolStyle.Solid,
    color = Color.fromRgba(0, 0, 255),
    width = 3f
    )
    // Create a polylineBuilder with a spatial reference and add three points to it.
    val polylineBuilder = PolylineBuilder(SpatialReference.wgs84()) {
    addPoint(-118.8215, 34.0139)
    addPoint(-118.8148, 34.0080)
    addPoint(-118.8088, 34.0016)
    }
    // then get the polyline from the polyline builder
    val polyline = polylineBuilder.toGeometry()
    // Create a polyline graphic with the polyline geometry and symbol.
    Graphic(
    geometry = polyline,
    symbol = polylineSymbol
    )
    }
    private val polygonGraphic by lazy {
    // Create a polygon builder with a spatial reference and add five vertices (points) to it.
    // Then get the polygon from the polygon builder.
    val polygonBuilder = PolygonBuilder(SpatialReference.wgs84()) {
    addPoint(-118.8189, 34.0137)
    addPoint(-118.8067, 34.0215)
    addPoint(-118.7914, 34.0163)
    addPoint(-118.7959, 34.0085)
    addPoint(-118.8085, 34.0035)
    }
    val polygon = polygonBuilder.toGeometry()
    // Create a red fill symbol with an alpha component of 128: values can run from 0 to 255).
    val polygonFillSymbol = SimpleFillSymbol(
    style = SimpleFillSymbolStyle.Solid,
    color = Color.fromRgba(255, 0, 0, 128),
    outline = blueOutlineSymbol
    )
    // Create a polygon graphic from the polygon geometry and symbol.
    Graphic(
    geometry = polygon,
    symbol = polygonFillSymbol
    )
    }
    @Composable
    fun MainScreen() {
    // create an ArcGISMap
    val map = remember {
    createMap()
    }
    // Create a graphics overlay.
    val graphicsOverlay = remember { GraphicsOverlay() }
    // Add the point graphic to the graphics overlay.
    graphicsOverlay.graphics.add(pointGraphic)
    // Add the polyline graphic to the graphics overlay.
    graphicsOverlay.graphics.add(polylineGraphic)
    // Add the polygon graphic to the graphics overlay.
    graphicsOverlay.graphics.add(polygonGraphic)
    // Create a list of graphics overlays used by the MapView
    val graphicsOverlays = remember { listOf(graphicsOverlay) }
    24 collapsed lines
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map,
    graphicsOverlays = graphicsOverlays
    )
    }
    }
    fun createMap(): ArcGISMap {
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }

Click Run > Run > app to run the app.

You should see a point, line, and polygon graphic around Mahou Riviera in the Santa Monica Mountains.

Alternatively, you can download the tutorial solution, as follows.

Option 2: Download the solution

  1. Click the Download solution link in the right-hand side of this page.

  2. Unzip the file to a location on your machine.

  3. Run Android Studio.

  4. Go to File > Open…. Navigate to the solution folder and click Open.

    On Windows: If you are in the Welcome to Android Studio dialog, click Open and navigate to the solution folder. Then click Open.

Since the downloaded solution does not contain authentication credentials, you must first set up authentication to create credentials, and then add the developer credentials to the solution.

Set up authentication

To access the secure ArcGIS location services ArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more used in this tutorial, you must implement API key authentication API key authentication is a type of authentication that uses an API key to authenticate requests to ArcGIS services and secure portal items. Learn more or user authentication User authentication is a type of authentication that allows users with an ArcGIS account to sign into an application and allow it to access ArcGIS content, services, and resources on their behalf. The typical authorization protocol used is OAuth2.0. Learn more using an ArcGIS Location Platform An ArcGIS Location Platform account, formerly known as an ArcGIS Developer account, is an identity associated with an ArcGIS Location Platform subscription. Learn more or an ArcGIS Online An ArcGIS Online account, also known as an ArcGIS Organization account, is an identity associated with an ArcGIS Online subscription. It can be used to access ArcGIS tools and develop applications with ArcGIS location services for an organization. Learn more account.

To complete this tutorial, click on the tab in the switcher below for your authentication type of choice, either API key authentication or User authentication.

Create a new API key access token An access token is an authorization string that provides access to secure ArcGIS content, data, and services. Its capabilities are determined by the privileges it supports. It is obtained by implementing API key authentication, User authentication, or App authentication. Learn more with privileges Privileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. Learn more to access the secure resources used in this tutorial.

  1. Complete the Create an API key tutorial and create an API key with the following privilege(s) Privileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. Learn more :

    • Privileges
      • Location services > Basemaps
  2. Copy and paste the API key access token into a safe location. It will be used in a later step.

Set developer credentials in the solution

To allow your app users to access ArcGIS location services ArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more , use the developer credentials that you created in the Set up authentication step to authenticate requests for resources.

  1. In the Android view of Android Studio, open app > kotlin+java > com.example.app > MainActivity. Set the AuthenticationMode to .API_KEY.

    MainActivity.kt
    14 collapsed lines
    package com.example.app
    import android.os.Bundle
    import androidx.activity.ComponentActivity
    import androidx.activity.compose.setContent
    import androidx.activity.enableEdgeToEdge
    import com.arcgismaps.ApiKey
    import com.arcgismaps.ArcGISEnvironment
    import com.arcgismaps.httpcore.authentication.OAuthUserConfiguration
    import com.arcgismaps.toolkit.authentication.AuthenticatorState
    import com.arcgismaps.toolkit.authentication.DialogAuthenticator
    import com.example.app.screens.MainScreen
    import com.example.app.ui.theme.TutorialTheme
    class MainActivity : ComponentActivity() {
    private enum class AuthenticationMode { API_KEY, USER_AUTH }
    private val authenticationMode = AuthenticationMode.API_KEY
    42 collapsed lines
    private val authenticatorState = AuthenticatorState()
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    when (authenticationMode) {
    AuthenticationMode.API_KEY -> {
    ArcGISEnvironment.apiKey = ApiKey.create("YOUR_ACCESS_TOKEN")
    }
    AuthenticationMode.USER_AUTH -> {
    authenticatorState.oAuthUserConfigurations = listOf(
    OAuthUserConfiguration(
    portalUrl = "https://www.arcgis.com",
    clientId = "YOUR_CLIENT_ID",
    redirectUrl = "YOUR_REDIRECT_URL"
    )
    )
    }
    }
    enableEdgeToEdge()
    setContent {
    TutorialTheme {
    MainScreen()
    if (authenticationMode == AuthenticationMode.USER_AUTH) {
    DialogAuthenticator(authenticatorState)
    }
    }
    }
    }
    }
  2. Set the apiKey property with your API key access token.

    MainActivity.kt
    22 collapsed lines
    package com.example.app
    import android.os.Bundle
    import androidx.activity.ComponentActivity
    import androidx.activity.compose.setContent
    import androidx.activity.enableEdgeToEdge
    import com.arcgismaps.ApiKey
    import com.arcgismaps.ArcGISEnvironment
    import com.arcgismaps.httpcore.authentication.OAuthUserConfiguration
    import com.arcgismaps.toolkit.authentication.AuthenticatorState
    import com.arcgismaps.toolkit.authentication.DialogAuthenticator
    import com.example.app.screens.MainScreen
    import com.example.app.ui.theme.TutorialTheme
    class MainActivity : ComponentActivity() {
    private enum class AuthenticationMode { API_KEY, USER_AUTH }
    private val authenticationMode = AuthenticationMode.API_KEY
    private val authenticatorState = AuthenticatorState()
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    when (authenticationMode) {
    AuthenticationMode.API_KEY -> {
    ArcGISEnvironment.apiKey = ApiKey.create("YOUR_ACCESS_TOKEN")
    }
    30 collapsed lines
    AuthenticationMode.USER_AUTH -> {
    authenticatorState.oAuthUserConfigurations = listOf(
    OAuthUserConfiguration(
    portalUrl = "https://www.arcgis.com",
    clientId = "YOUR_CLIENT_ID",
    redirectUrl = "YOUR_REDIRECT_URL"
    )
    )
    }
    }
    enableEdgeToEdge()
    setContent {
    TutorialTheme {
    MainScreen()
    if (authenticationMode == AuthenticationMode.USER_AUTH) {
    DialogAuthenticator(authenticatorState)
    }
    }
    }
    }
    }

Best Practice: The access token is stored directly in the code as a convenience for this tutorial. Do not store credentials directly in source code in a production environment.

Run the app

Click Run > Run > app to run the app.

You should see a point, line, and polygon graphic around Mahou Riviera in the Santa Monica Mountains.

What’s next

Learn how to use additional API features, ArcGIS location services, and ArcGIS tools in these tutorials: