Hi Team,
We are using ArcGIS map in Android OS. We were able to plot a pin on map. But unable to drag and place it on the appropriate map location. We need guidance for Drag and Move.
Your help is much needed to sort out this feature.
Thanks,
Mohan Narasimman
To move the location of a graphic on the map, use the following steps:
Below is an example of a "PictureMarkerSymbol" that is placed on the map on a single tap, and can be dragged to a new location on a double-tap drag.
mapView.onTouchListener =
object : DefaultMapViewOnTouchListener(this@MainActivity, mapView) {
// drag a graphic to a new point on map
override fun onDoubleTouchDrag(e: MotionEvent): Boolean {
// identify the pixel at the given screen point
val screenPoint = android.graphics.Point(e.x.roundToInt(), e.y.roundToInt())
// create a map point from the screen point
val mapPoint: Point = mapView.screenToLocation(screenPoint)
// find the map view interaction type
when (e.action) {
// user selected the graphic
MotionEvent.ACTION_DOWN -> {
// from the graphics overlay, get the graphics near the tapped location
val identifyResultsFuture: ListenableFuture<IdentifyGraphicsOverlayResult> =
mapView.identifyGraphicsOverlayAsync(
graphicsOverlay,
screenPoint,
10.0,
false
)
identifyResultsFuture.addDoneListener {
// identify the selected graphic
val identifyGraphicsOverlayResult: IdentifyGraphicsOverlayResult =
identifyResultsFuture.get()
val graphics = identifyGraphicsOverlayResult.graphics
if (graphics.isEmpty()) {
showError("No graphic at point")
} else {
// clear the current graphic position
graphicsOverlay.graphics.clear()
// get the first graphic identified
identifiedGraphic = graphics[0]
}
}
}
// user is moving the graphic
MotionEvent.ACTION_MOVE -> {
// clear the current graphic position
graphicsOverlay.graphics.clear()
val graphic = Graphic(mapPoint, pictureMarkerFromUri)
graphicsOverlay.graphics?.add(graphic)
}
// user released the graphic
MotionEvent.ACTION_UP -> {
// release selected graphic
identifiedGraphic = null
}
}
return true
}
// place a new graphic on map
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
// clear the current graphic position
graphicsOverlay.graphics.clear()
// create a screen point from where the user tapped
val screenPoint = android.graphics.Point(e.x.roundToInt(), e.y.roundToInt())
// create a map point from the screen point
val mapPoint: Point = mapView.screenToLocation(screenPoint)
// create graphic with the location and symbol and add it to the graphics overlay
val graphic = Graphic(mapPoint, pictureMarkerFromUri)
graphicsOverlay.graphics?.add(graphic)
return true
}
}