Delete marker from a button

0

By clicking on the marker, I get your ID

mMap = googleMap;
    mMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(this, R.raw.tema_gris));
    this.miUbicacion();
    mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener()
    {
        @Override
        public boolean onMarkerClick(Marker marker) {
            marcador_seleccionado=marker.getID(); //<<<<<<<<<<<<<<<<<<<<<<<<<<
            if (marker.getTitle() != null) {

...

I would like to delete the problem afterwards from a button but I do not know how to eliminate it with knowing the Id of the bookmark, or some other recommendation.

    
asked by DoubleM 20.12.2017 в 09:36
source

1 answer

2

What you can do is, when creating the markers, save them in a list of Markers.

//Creamos el arraylist para guardar los marcadores
ArrayList<Marker> listadoMar = new ArrayList<Marker>();

//Creamos el marcador
Marker mar = googleMap.addMarker(new MarkerOptions()
                .position(position)
                .title(rV.Get_descripcion())
                .snippet(txt_infoTodas).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));

//añadimos el marcador a la lista
listadoMar.add(marker);

...........................
//Cuando vayas a eliminar si tenemos el id del marker a borrar recorremos la lista y eliminamos este marcador
for(int i = 0; i<listadoMar.size; i++)
{
    if(listadoMar.get(i).getId()==id){ //Comparamos los id de los marcadores de la lista con el del marker que queremos eliminar
        listadoMar.remove(listadoMar.get(i));
    }
}

//Ahora que hemos eliminado el marcador, recargamos el mapa
map.clear();  //Primero eliminamos lo que había en el mapa

for(int i = 0; i<listadoMar.size; i++)  //Añadimos todos los marcadores otra vez
{
    map.addMarker(listadoMar.get(i));
}

Another option you have is to hide the bookmark by calling:

Marker.setVisible(false);

You would call this method instead of remove, it depends on what works best for you.

Response obtained from: link

    
answered by 20.12.2017 в 09:54