title: Array of polygons on MapView
body: <p>I am creating a <code>mapView</code> with coordinates being downloaded from a XML file. I already have the coordinates parsed out like I want them to be but right know I'm hard coding the them, I have two problems the first is what's the best way to feed the points an array of <code>GeoPoints</code>"From XML File"? The second issue is that I cannot get the polygons to separate. I have five coordinates for each polygon view. The issue is it is connecting the polygons as if it was one. Can somebody tell me what I am doing wrong or is there something else I need to be doing. Below is what I currently have any help would be appreciated.</p>
  
  <p>Ok I have an update to my original question, I got the array part working from the xml using <a href="https://stackoverflow.com/questions/11124584/howto-ontouch-on-a-paint-overlay-googlemaps">Laire's question</a>. So all of the coordinate are being downloaded to the map from the xml file but the issues is they are connected as if it is one set of coordinates. see <img src="https://i.stack.imgur.com/MUIWV.png" alt="map with polygons">. </p>
  
  <p>Here is the code that I have so fair in my mainActivity.java</p>
  
  <pre><code>public class MapViewActivity extends MapActivity {
  ArrayList&lt;HashMap&lt;String, Object&gt;&gt; boslst;
  MapView mapView; 
  MapController mapcontrol;
  GeoPoint p;
  Polygon polygon;
  
  private static final class LatLonPoints extends GeoPoint { 
      public LatLonPoints(double latitude, double longitude) { 
          super((int) (latitude * 1E6), (int) (longitude * 1E6)); 
      } 
  } 
  public static BigDecimal round(float d, int decimalPlace) {
      BigDecimal bd = new BigDecimal(Float.toString(d));
      bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);      
      return bd;
  
  }  
  @Override
  protected boolean isRouteDisplayed() {
      return false;
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
  
  
      String coordinates[] = {"35.20418", "-89.86862"};
      double lat = Double.parseDouble(coordinates[0]);
      double lng = Double.parseDouble(coordinates[1]);
  
      p = new GeoPoint(
              (int) (lat * 1E6), 
              (int) (lng * 1E6));
  
      MapView mapView = (MapView) findViewById(R.id.mapview);
      mapcontrol = mapView.getController();
      mapcontrol.animateTo(p);
      mapcontrol.setZoom(10);
      mapView.setBuiltInZoomControls(true);
  
      ArrayList&lt;GeoPoint&gt; points = new ArrayList&lt;GeoPoint&gt;();
      try {
  
          URL url = new URL(
                  "my url");
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          DocumentBuilder db = dbf.newDocumentBuilder();
          Document doc = db.parse(new InputSource(url.openStream()));
          doc.getDocumentElement().normalize();
  
          NodeList nodeList = doc.getElementsByTagName("Section");
  
  
          for (int i = 0; i &lt; nodeList.getLength(); i++) {
  
              Node node = nodeList.item(i);
  
              Element locElement = (Element) node;
              NodeList nameList = locElement.getElementsByTagName("coords");
  
  
              int locationCount = nameList.getLength();
  
          for (int j = 0; j &lt; nameList.getLength(); j++) {
  
              Node nodel = nameList.item(j);
  
              Element fstElement = (Element) nodel;
              NodeList nameL = fstElement.getElementsByTagName("coords");
              Element nameE = (Element) nameL.item(0);
              nameL = nameE.getChildNodes();
  
              String latit = ((Node) nameL.item(0)).getNodeValue();
              String[] latt = latit.split(",");
              BigDecimal latitude = round(Float.parseFloat(latt[0]),5);
              BigDecimal longitude = round(Float.parseFloat(latt[1]),5);
  
  
              double Lat = latitude.doubleValue();
              double Long =  longitude.doubleValue();
  
  
              points.add(new LatLonPoints(Lat,Long));
              polygon = new Polygon(points);
        }
              polygon = new Polygon(points);
  
          }
      }catch (Exception e) {
          Log.e("APP","Failed", e);
      }        
  
      mapView.getOverlays().clear();
      mapView.getOverlays().add(polygon);
      mapView.invalidate();
  }
  </code></pre>
  
  <p>Polygon.java</p>
  
  <pre><code>public class Polygon extends Overlay {
  ArrayList&lt;GeoPoint&gt; geoPoints;
  
  public Polygon(ArrayList&lt;GeoPoint&gt; points){
      geoPoints = points;
  }
  
  @Override
  public void draw(Canvas canvas, MapView mapView, boolean shadow){
      //Set the color and style
      Paint paint = new Paint();
      paint.setColor(Color.parseColor("#88ff0000"));
      paint.setAlpha(50);
      paint.setStyle(Paint.Style.STROKE);
  
      //Create path and add points
      Path path = new Path();
      Point firstPoint = new Point();
      mapView.getProjection().toPixels(geoPoints.get(0), firstPoint);
      path.moveTo(firstPoint.x, firstPoint.y);
  
      for(int i = 1; i &lt; geoPoints.size(); ++i){
          Point nextPoint = new Point();
          mapView.getProjection().toPixels(geoPoints.get(i), nextPoint);
          path.lineTo(nextPoint.x, nextPoint.y);
      }
  
      //Close polygon
      path.lineTo(firstPoint.x, firstPoint.y);
      path.setLastPoint(firstPoint.x, firstPoint.y);
      canvas.drawPath(path, paint);
      super.draw(canvas, mapView, shadow);
  
   }
   }
  </code></pre>
  
  <p>So my question what do I have to do to get the polygon to build one at a time and not act as one?</p>