Remove Marker in Specific Android Studio

-1

I have the following query, I am creating an App that will add several Markers on the map, until all right, but at the time I want to modify from the database the location of one of the marker, the system does not know which one Marker is the one who has to move.

By chance there is some way to put a unique id to the marker, or create some kind of dynamic variable, which allows me to identify which marker corresponds.

    double latitud = Double.parseDouble(lat);
    double longitud = Double.parseDouble(lon);

   LatLng coordenadasBuses = new LatLng(latitud,longitud);
   MarkerOptions().position(coordenadasBuses).title(idBuses));
    if (market != null){
        market.remove();
    }

   market= MainActivity.mMap.addMarker(new MarkerOptions()
            .position(coordenadasBuses)
            .icon(BitmapDescriptorFactory.defaultMarker())
    );

The variable Market is a Global variable, so only this variable is used to add the Markers, I know that is an error, because he does not know which of the markets he has to eliminate.

Thanks for any input.

    
asked by AndreyC1995 21.02.2018 в 18:23
source

1 answer

1

First you get the String of the id of your database:

String id = Long.toString(TUCOLUMNA_ID); //de SQLite
String id = String.valueOf(Integer.parseInt(jsonObject.getString(ID))); // de MySql

You compare that string and add the marker you want, as in this case 2 different colors:

if ("1".equals(id)) {
 mMap.setInfoWindowAdapter(adapter);
 mMap.addMarker(new MarkerOptions().position(latLng).title(title).rotation(0).snippet(title + "\n" + "ejemplo de marker")
 .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));

   }else if ("2".equals(id)){
    mMap.setInfoWindowAdapter(adapter);
    mMap.addMarker(new MarkerOptions().position(latLng).title(title).rotation(0).snippet("otro ej")
    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));

    } else if (...
    
answered by 23.02.2018 в 00:00