How to remove specific bookmarks from a googlemap

So this app works like this: the user enters a journey that goes from Point C (collection) to point E (delivery).

These points are shown on the map, in the form of markers, as in the figure below.

Example map with markers

Now I need to remove the markers when clicking on the X.

The general concept is like this: I will make a list containing (string ID, marker marker, Marker marker) and each new marker adds a row to this list no addMarker () method.

Yes, the removeMarker(string ID) method will retrieve the markers relative to the ID and remove them from the map, when the user deletes the journey.

My research indicated several possible approaches. It could create a Class, A list, a hashmap, etc.

I would like opinions on the best way to do this and if possible, code examples.

Note that adding the bookmarks already works and removing the registry as well. And rightly so at this point I will call the removeMarker () method.

I think the question can be summarized as: what is the best way to create a list with string, Marker, Marker types?

Author: Rene Freak, 2017-01-12

2 answers

The solution was like this.

In the recyclerView adapter's delete (X) button listener, we delete the record and then call the method in MainActivity:

holder.ivDelete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ...
            ...  
            runDbHelper.deleteRow(runId);
            ((MainActivity) v.getContext()).removeMarkersFromMap(runId);
            ...
            ... 
        }
    });

The removal method in MainActivity, receives the ID and passes to the fragment:

public  void removeMarkersFromMap(String ID) {
    if (ID != null) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        MarkersFragment mFragment = null;
        if (getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE) {
            mFragment = (MarkersFragment) fragmentManager.findFragmentById(R.id.markersMapPanel);
        } else if (getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT) {
            mFragment = (MarkersFragment) fragmentManager.findFragmentById(R.id.viewpager);
        }
        if (mFragment != null) {
            mFragment.removeMarkers(ID);
        }
    }

}

This, in turn, executes the method on the map fragment that deletes the marker (s).

public void removeMarkers(String id){

    MarkersPair markersPair = markersPairHashMap.get(id);
    if(markersPair != null){
        if(markersPair.collect != null) {
            markersPair.collect.remove();
        }
        if(markersPair.delivery != null) {
            markersPair.delivery.remove();
        }
    }
}

And, no more comedy!

 4
Author: Rene Freak, 2017-01-12 23:56:08

I have a screen that displays some points on a map; according to the user's action it is necessary to update this map by hiding/displaying some markers. What we did was keep the points already loaded and control these actions in javascript.

var marcadores = {}; //seria array de [ID] -> marcadores

...
function LimparMarcadores () {
    for (var i = 0; i < marcadores[id].length; i++) {
        if (marcadores[id][i] != "0")
            marcadores[id][i].setMap(null);
    }

    marcadores[id] = [];
}
 0
Author: rLinhares, 2017-01-12 17:03:52