Removing specific markers from a googlemap

3

So this app works like this: the user enters a journey 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.

Now I need to remove markers by clicking on X.

The general concept is like this: I will make a list containing (String ID, Marker markerDe, Marker markerTo) and each new marker adds a line to this list in the addMarker () method.

Dai, the removeMarker (String ID) method will retrieve ID-related markers and remove them from the map when the user excludes the journey.

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

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

Note that adding the bookmarks already works and removing the record as well. And just at this point I'm going to call the removeMarker () method.

I think the question can be summarized in: What is the best way to create a list with types String, Marker, Marker?

    
asked by anonymous 12.01.2017 / 16:52

2 answers

4

The solution went like this.

In the deleteclient (X) listener of the recyclerView adapter, 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 it 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 excludes 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();
        }
    }
}

e, finite comedy!

    
13.01.2017 / 00:56
0

I have a screen that displays some points on a map; according to the action of the user 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] = [];
}
    
12.01.2017 / 18:03