Tino
Tino

Reputation: 1

Marker in osmdroid map

I created a mapView in AndroidStudio's project using the osmdroid library, in this way:

mapView = findViewById(R.id.mapView)
mapView.setTileSource(TileSourceFactory.MAPNIK)
mapView.setMultiTouchControls(true)

then I created a marker on the map:

  thePoint = GeoPoint(lat, long)
    
  val mapController = mapView.controller
  mapController.setZoom(15.0)
  mapController.setCenter(thePoint)
    
  val marker = Marker(mapView).apply {
      position = thePoint                 
      title = label                      
      isDraggable = true                 
      icon = context.getDrawable(id)     
      setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM)
      }
 mapView.overlayManager.add(marker)

Now I see correctly the marker on my map.The problem is that the marker is not draggable... What I'm forgetting?

Upvotes: 0

Views: 48

Answers (1)

Tino
Tino

Reputation: 1

Finally, I resolved adding a custom mapView.setOnTouchListener, Following you can find an example:

    mapView.setOnTouchListener { _, event ->
        when (event.action) {
           MotionEvent.ACTION_DOWN -> {
             <my code for mouse's click down>
           }
           MotionEvent.ACTION_MOVE -> {
             <my code for mouse's dragging>
           }
           MotionEvent.ACTION_UP -> {
             <my code for mouse's click up>
           }
        }

Upvotes: 0

Related Questions