Skip to content

Add a point, line, and polygon

Learn how to display point, line, and polygon graphics in a map.

add a point line and polygon

You typically use graphics 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, symbol, and attributes.

In this tutorial, you display points, lines, and polygons on a map as graphics.

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
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 @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. 

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
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 @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,   )  } 
    Expand
  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
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 @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) } 
    Expand
  3. Pass graphicsOverlays as the graphicsOverlays argument to MapView.

    MainScreen.kt
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163  Scaffold(  topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }  ) {  MapView(  modifier = Modifier.fillMaxSize().padding(it),  arcGISMap = map,   graphicsOverlays = graphicsOverlays   )  } 
    Expand

Add a point graphic

A point graphic is created using a point and a marker symbol. A point is defined with x and y coordinates, and a spatial reference. 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
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 // Create a blue outline symbol. private val blueOutlineSymbol by lazy {  SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(0, 0, 255), 2f) } 
    Expand
  2. Create a lazy top-level property named pointGraphic.

    MainScreen.kt
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 private val pointGraphic by lazy {  } 
    Expand
  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
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 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  } 
    Expand
  4. Create a Graphic with point and simpleMarkerSymbol.

    MainScreen.kt
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 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  )  } 
    Expand
  5. In MainScreen, display the graphic by adding it to the graphics property of graphicsOverlay.

    MainScreen.kt
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 @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) } 
    Expand

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 is created using a polyline and a line symbol. A polyline is defined as a sequence of points.

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

    MainScreen.kt
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 private val polylineGraphic by lazy {  } 
    Expand
  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
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 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()  } 
    Expand
  3. Create a Graphic with polyline and polylineSymbol.

    MainScreen.kt
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 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  )  } 
    Expand
  4. In MainScreen, display the graphic by adding it to the graphics property of graphicsOverlay.

    MainScreen.kt
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 @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) } 
    Expand

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 is created using a polygon and a fill symbol. 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
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 private val polygonGraphic by lazy {  } 
    Expand
  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
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 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  )  } 
    Expand
  3. Create a Graphic with polygon and polygonFillSymbol.

    MainScreen.kt
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 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  )  } 
    Expand
  4. In MainScreen, display the graphic by adding it to the graphics property of graphicsOverlay.

    MainScreen.kt
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 @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) } 
    Expand

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 used in this tutorial, you must implement API key authentication or user authentication using an ArcGIS Location Platform or an ArcGIS Online account.

Create a new API key access token with privileges 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
      • 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, 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
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 class MainActivity : ComponentActivity() {   private enum class AuthenticationMode { API_KEY, USER_AUTH }   private val authenticationMode = AuthenticationMode.API_KEY 
    Expand
  2. Set the apiKey property with your API key access token.

    MainActivity.kt
    Expand
    Use dark colors for code blocks
    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 49 50 51 52 53 54 55 56 57 58 59 60 61 62  override fun onCreate(savedInstanceState: Bundle?) {  super.onCreate(savedInstanceState)   when (authenticationMode) {  AuthenticationMode.API_KEY -> {   ArcGISEnvironment.apiKey = ApiKey.create("YOUR_ACCESS_TOKEN")   } 
    Expand

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:

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