In the new Google Maps API for Android, we can add a marker , but there is no (easy) way to remove it.
My solution is to save the markers on the map and redraw the map when I want to remove the marker, but this is not very efficient.
private final Map<String, MarkerOptions> mMarkers = new ConcurrentHashMap<String, MarkerOptions>(); private void add(String name, LatLng ll) { final MarkerOptions marker = new MarkerOptions().position(ll).title(name); mMarkers.put(name, marker); runOnUiThread(new Runnable() { @Override public void run() { mMap.addMarker(marker); } }); } private void remove(String name) { mMarkers.remove(name); runOnUiThread(new Runnable() { @Override public void run() { mMap.clear(); for (MarkerOptions item : mMarkers.values()) { mMap.addMarker(item); } } }); }
Does anyone have a better idea?
android google-maps
Jonas Dec 03 2018-12-12T00: 00Z
source share