title: Removing Markers in android
body: <p>I have a Global array Object like <code>Marker marker_array[];</code> and later in Layout click I initialized it as <code>marker_array = new Marker[8];</code>. I want to add markers to map on that layout and remove on 2nd click so I created <code>clickcount</code> Global variable with zero value.</p>
  
  <p>My proper code is here</p>
  
  <pre><code>final RelativeLayout layout = (RelativeLayout) findViewById(R.id.track_div);
  
          layout.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  clickcount++;
  
                   point_new = new LatLng[8];
                  point_new[0] = new LatLng(31.5301843, 74.3207487);
                  point_new[1] = new LatLng(31.5214693,74.3236027);
                  point_new[2] = new LatLng(31.5194393, 74.3257327);
                  point_new[3] = new LatLng(31.4942166, 74.3004533);
                  point_new[4] = new LatLng(31.4864646, 74.2911203);
                  point_new[5] = new LatLng(31.4803596, 74.2787933);
                  point_new[6] = new LatLng(31.4764716, 74.2638203);
                  point_new[7] = new LatLng(31.4775236, 74.2628873);
  
  //  initialize marker_array;
                  marker_array = new Marker[8];
  
                  Toast.makeText(getApplicationContext(), "count "+clickcount, Toast.LENGTH_SHORT).show();
  //
                  if (clickcount % 2 == 0) {
                      polyline.setVisible(false);
  
  
                      for (int i = 0; i &lt; point_new.length; i++){
  
                          Toast.makeText(getApplicationContext(), "marker length ="+marker_array.length, Toast.LENGTH_SHORT).show();
  
                          marker_array[i].remove();
  
  //                     marker_array.setVisible(false);
  
                      }
                  } else {
                      polyline.setVisible(true);
  
   for (int i = 0; i &lt; point_new.length; i++) {
                       //   marker_array = new Marker[point_new.length];
                      MarkerOptions markerOptions = new MarkerOptions()
                              .position(point_new[i]);
  
                           marker_array[i] = mMap.addMarker(markerOptions);
                          marker_array[i].setTitle("Points");
                      marker_array[i].setSnippet("Distance = 9.6 km, Time = 20 minute/s");
                      marker_array[i].setIcon(BitmapDescriptorFactory.fromResource(R.drawable.bus));
  
  
                      }
                  }
  </code></pre>
  
  <p>The problem is that it creates all 8 markers But does not remove, Even if in if condition where I'm trying to remove markers <code>Toast</code> shows proper length <code>8</code>. <strong>Butt</strong> when I remove any of the <code>marker_array</code> separately as <code>marker_array[7]</code> it removes it.</p>
  
  <p>How can I remove all the markers in <strong>marker_array</strong> without <code>map.clear();</code> method because I have some other things like polyline etc that I do not want to remove.</p>
  
  <p>Any effort will be appreciated. </p>