0

I want when I set more than two markers they to disappear.

I wrote this code but it seems is not working.

Thanks in advance.

MarkerOptions markerOptions = new MarkerOptions();
            markerOptions.position(latLng);
            markerOptions.title(addressText);

            map.addMarker(markerOptions);

 List<MarkerOptions> aList = new ArrayList<MarkerOptions>();
            aList.add(markerOptions);

            int p;

            for(p = 0; p<aList.size(); p++){

            }

            if(p>2){

                map.clear();
            }
cross_flame
  • 840
  • 2
  • 11
  • 24
  • check this solution http://stackoverflow.com/questions/16853182/android-how-to-remove-all-markers-from-google-map-v2 – Mina Tadros Feb 09 '14 at 09:24

1 Answers1

0

Whats your error message?

Your code isn't very clear. Where is markerOptions coming from? Is it meant to be more than one? You might need a loop to add them, or use .addAll.

Your for loop is pretty redundant too.

Try something more like this:

List<MarkerOptions> aList = new ArrayList<MarkerOptions>();

aList.addAll(markerOptions);

if(aList.size()>2)
{
    map.clear();
}
ISeeSharp
  • 315
  • 1
  • 9