How i can remove marker with a ToogleButton?

Viewed 23

I need the "else" part to delete the bookmarks created only by that button.

I have used the map.clear() parameter, but it deletes the entire map and since I have other buttons that I want to perform the same function, I need to individually remove the markers that each button creates

    val dominos: ToggleButton = findViewById(R.id.btndominos)
    // set on-click listener
    dominos.setOnCheckedChangeListener { _, isChecked ->
        if (isChecked) {
            val coordenadas = LatLng(40.320360, -3.865281)
            val marker: MarkerOptions =
                MarkerOptions().position(coordenadas).title("Dominos Pizza Mostoles")
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.dominospizza))
            mapa.addMarker(marker)
        } else {
            ??
        }
    }
0 Answers
Related