Select to view content in your preferred language

To add point on map on button click

495
1
04-16-2023 11:52 PM
komalzoting
Emerging Contributor

Hii all,

I am new to ArcGIS runtime SDK for android. I want to add a point on map on button click like Field Maps mobile app by ESRI where by clicking on 'Add Point' button, point added on map according to crosshair position on map . please help regarding the same thanx in advance  

1 Reply
Shubham_Sharma
Esri Contributor
// create and style graphic with symbol to be added to the map
val locationGraphic = Graphic().apply {
    symbol = SimpleMarkerSymbol(SimpleMarkerSymbol.Style.X, Color.MAGENTA, 15f)
}

// create a graphics overlay to add the graphic
val graphicsOverlay = GraphicsOverlay().apply {
    graphics.add(locationGraphic)
}

// add the graphics overlay to the MapView
mapView.graphicsOverlays.add(graphicsOverlay)

addPointButton.setOnClickListener {
    val screenPoint = android.graphics.Point(xPosition, yPosition)
    // create a map point from the screen point
    val mapPoint: Point = mapView.screenToLocation(screenPoint)
    // show graphic at the screen point
    locationGraphic.geometry = mapPoint
}
0 Kudos