How does one implement drag and drop for Android marker?

前端 未结 6 1253
终归单人心
终归单人心 2020-11-29 23:20

Hi? I am working on a MapView app in Android. I have three markers that I want to be able to use the Google Map API getlocation-function on, later on. In order to try it out

6条回答
  •  没有蜡笔的小新
    2020-11-30 00:07

    Below is the answer to Kotlin Lover! It's quite very simple! As you can see below.

       googleMap.addMarker(
            MarkerOptions()
                .position(latLatLng).draggable(true)
        )
    

    Below is the liner code for getting the end dragging location

       mMap.setOnMarkerDragListener(object : GoogleMap.OnMarkerDragListener {
            override fun onMarkerDragStart(arg0: Marker) {
    
            }
    
            override fun onMarkerDragEnd(arg0: Marker) {
                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(arg0.position, 1.0f))
                val message = arg0.position.latitude.toString() + "" + arg0.position.longitude.toString()
                Log.d(TAG + "_END", message)
            }
    
            override fun onMarkerDrag(arg0: Marker?) {
                val message = arg0!!.position.latitude.toString() + "" + arg0.position.longitude.toString()
                Log.d(TAG + "_DRAG", message)
            }
        })
    

    If you have any doubt then you can comment into the comment box! Happy Coding

提交回复
热议问题