How i can remove marker with a ToogleButton?


This Content is from Stack Overflow. Question asked by Jarek Palomino

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(
    // 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")
        } else {


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?