如果我在Kotlin Android的Google map中使用其他标记单击,我想使用其他putExtra。
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)
}
感谢您的帮助
添加标记时添加标记参数,并根据标记检查标记单击,如下所示:
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))
您可以按照以下方法添加标记点击侦听器,并根据标记传递意图附加功能:
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
}
希望这可以帮助!
谢谢您的回答
.tag参数无法解析,对不起,我第一次使用kotlin。但我认为您的回答可以奏效。
更新了代码,请检查一次。
是的,我明白了
真的很谢谢你