RobFos
RobFos

Reputation: 17

Android after i use map.clear cant add markers

I have a method to a add markers to google map v2 and i wish to clear the markers and then add more markers all while in the map. This is how i add the markers which works fine mapLoc being the map itself. Further down the line i then call mapLoc.clear which gets rid of the markers.

I then wish to add more markers to the map but the markers dont appear when i call this method any help?

        for(int i=0;i<list.size();i++){

           LatLng lg=new LatLng(Float.parseFloat(list.get(i).get(5)), Float.parseFloat(list.get(i).get(6)));

           Marker mark= mapLoc.addMarker(new MarkerOptions().position(lg)
                .title(list.get(i).get(0)).snippet(list.get(i).get(1)).icon(BitmapDescriptorFactory
                          .fromResource(R.drawable.mark2)));
        counter++;
        }

Upvotes: 1

Views: 573

Answers (1)

bjiang
bjiang

Reputation: 6078

As we discuss above:

Try to save your Marker object in the HashMap, and then calling markers.remove() instead of map.clear, finally use your code above to add additional markers.

For more details, please refer to here.

Upvotes: 2

Related Questions