Issue
I'm writing an application using Kotlin and GoogleMap. I've got the map and I tried to set an OnMapClick listener that only logs a message. The build is ok, but when I click on the map, nothing happens.
I've looked for documentation but I found nothing about a problem like this.
Here the code of the map:
class map : FragmentActivity(), OnMapReadyCallback {
private var mMap: GoogleMap? = null
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
mMap?.setOnMapClickListener {
GoogleMap.OnMapClickListener { p0 -> Log.d("Map", p0.toString()) }
}
}
}
I found a lot of documentation about GoogleMap in Java, but nothing in Kotlin, so I tried this by my own. Thanks for helping me to find what's wrong with this code.
Solution
You’re passing a lambda to setOnMapClickListener by using {}. In fact, you simply want to pass the GoogleMap.OnMapClickListener as an argument, which will work with parentheses. So change your code to setOnMapClickListener(GoogleMap.OnMapClickListener())
Answered By - s1m0nw1
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.