I want to have a different putExtra if I click with a different Marker in my google map with Kotlin Android.
mMap.addMarker(
MarkerOptions()
.position(concessionnaireTest)
.title("test")
.snippet("Numéro : *******")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))
)
mMap.addMarker(
MarkerOptions()
.position(concessionnaireTestsecond)
.title("test2")
.snippet("Numéro : *******")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))
)
mMap.moveCamera(CameraUpdateFactory.newLatLng(concessionnaireTest))
mMap.setOnInfoWindowClickListener {
intent.putExtra("info", "testing")
startActivity(intent)
}
Thank you for helping
Add tag parameter while adding marker and check the marker click according to the tag as below:
mMap.addMarker(
MarkerOptions()
.position(concessionnaireTest)
.title("test")
.snippet("Numéro : *******")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)))?.tag="test1"
mMap.addMarker(
MarkerOptions()
.position(concessionnaireTestsecond)
.title("test2")
.snippet("Numéro : *******")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)))?.tag="test2"
mMap.moveCamera(CameraUpdateFactory.newLatLng(concessionnaireTest))
Here's how you can add marker click listener and according to tag pass the intent extras:
mMap?.setOnMarkerClickListener { marker ->
val markerTag = marker?.tag
markerTag?.let {
when (markerTag) {
"test1" -> {
intent.putExtra("info", "testing1")
startActivity(intent)
}
"test2" -> {
intent.putExtra("info", "testing2")
startActivity(intent)
}
else -> {
}
}
}
true
}
Hope this helps!
Thank you for your answer
the .tag parameter is unresolved reference sorry i use kotlin for the first time. But I think your answer can work.
Updated the code for tag please check once.
Yes I see thank
It's work thank you very much