How to Set click listener on marker in google map?

Viewed 17900

i have two marker in example where one is for current location and one is for destination i have drawn a Route path between them but now in same example i want to set a click listener on both the marker can you suggest some good example related this ..?

3 Answers

Here is how to do it using Kotlin:

private lateinit var mMap: GoogleMap  //declaration inside class

override fun onMapReady(googleMap: GoogleMap) {
    mMap = googleMap
    mMap.setOnMarkerClickListener { marker ->
        if (marker.isInfoWindowShown) {
            marker.hideInfoWindow()
            } else {
            marker.showInfoWindow()
            }
        true
        }
}

Hope this helps some beginner like me.

Related