title: Memory efficient google map drawing on Android
body: <p>I'm trying to draw several spots on a GoogleMap using APIv2 on Android with support libraries.
  I have several arrays of SPOT objects, containing latitude and longitude of said spots.
  Each time I want to draw the spots on the map, I call the following method:</p>
  
  <pre><code>public void drawSpotsFromArray(ArrayList&lt;Spot&gt; pSpots, int pZIndex) {
  
      for (int i=0; i&lt;pSpots.size(); i++) {
          Spot lSpot = pSpots.get(i);
  
          double lDiameter = 10;
  
          CircleOptions lCircleOptions = new CircleOptions();
          lCircleOptions.center(new LatLng(lSpot.mLatitude, lSpot.mLongitude));
          lCircleOptions.radius(lDiameter);
          lCircleOptions.strokeColor(Color.BLACK);
          lCircleOptions.strokeWidth(5);
          lCircleOptions.fillColor(Color.WHITE);
          lCircleOptions.zIndex(pZIndex);
  
          mGoogleMap.addCircle(lCircleOptions);
      }
  }
  </code></pre>
  
  <p>It just draws every spot contained in the array.<br>
  Now, my problem is that these arrays are quite big, resulting in a memory overload. I draw about 500 circles (5 arrays of 100 circles), so the app gets very slow.</p>
  
  <p>Is there a way, instead of drawing each circle as a single overlay, draw each table of spots as a single overlay? For example, drawing 100 circles of an array as one overlay, resulting in 5 overlays (5 arrays) instead of 500 overlays (the arrays' circles).</p>
  
  <p>If so, would it be more memory-efficient?<br>
  If not, what would be the best practice to draw these circles without consuming all the device's memory?</p>
  
  <p>Each time I call this method, I give a higher zIndex. I don't know if this is impacting the memory in any way.
  Thank you for your help.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>OK, the algorithm in the answers below helped me to solve my problem, along with this thread to draw a ground overlay with a drawable:
  <a href="https://stackoverflow.com/questions/18062363/overlay-an-image-on-google-maps-android-api-v2">Ground Overlay</a></p>
  
  <p>Thanks for your help!</p>