温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - How change the intent.putExtra when you click in a different marker with google map & Kotlin Android
android google-maps kotlin

其他 - 当您使用Google Map和Kotlin Android单击其他标记时如何更改intent.putExtra

发布于 2020-03-28 23:39:16

如果我在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)

    }

感谢您的帮助

查看更多

查看更多

提问者
Tytanpolo
被浏览
99
Bhoomi 2020-01-31 21:02

添加标记时添加标记参数,并根据标记检查标记单击,如下所示:

 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
    }

希望这可以帮助!