Home > Software design >  Use onClick on google maps markers in kotlin
Use onClick on google maps markers in kotlin

Time:12-09

I'm actually working on a pokemon GO like game on Android Studio and I would like to assign an onClick listener on google maps markers in kotlin. I'm working with compose but I don't find the way to add the onClick on my marker. Actual code

Thank you !

CodePudding user response:

You can use the setOnMarkerClickListener for marker click.

    // on below line we are adding click listener for our marker
    mMap.setOnMarkerClickListener { marker: Marker ->
    
    // on below line we are displaying a toast message on clicking on marker
    Toast.makeText(context, "Clicked location is "   marker.title, Toast.LENGTH_SHORT).show()     
    
    false
    }
  • Related