title: GoogleMaps API V3 Build Polygon Containing Multiple ZipCodes
body: <p>I have to allow a user to input multiple zip codes, retrieve the latitude and longitude from a database and then build a huge polygon that encompasses them.</p>
  
  <p>I'm coding in Java and using Google Maps API V3. I have no problem doing a single zip code build. But upon adding more zip codes the polylines that are generated go hay-wire and distort the polygon, as pictured below. 
  <img src="https://i.stack.imgur.com/tf7cp.jpg" alt="fussy google map polygon"></p>
  
  <p>What do I need to change in my code to make all these smaller polygons into one larger one? I've scoured Google for answers and all I've managed to come across is building each zip code's polygon individually but that still won't give me a end result of a larger, single polygon. </p>
  
  <p>Currently, after the zip codes are inputted the program collects the lat and long points from the database and feeds them into a giant array of arrays (a String[][] to be exact), which is then passed the the html and javascript to generate the resulting polygon.</p>
  
  <p>My javascript is highly similar to the GoogleMaps API V3 simple polygon example:</p>
  
  <pre><code>function clearHello(coords1){
  coords = coords1
  var triangleCoords = new Array();
  var l = coords.length;
  for (var x = 0; x &lt; l; x++){
  triangleCoords[x] = new google.maps.LatLng( coords[x][0], coords[x][1]);
  }
  // Construct the polygon.
  bermudaTriangle = new google.maps.Polygon({
  paths: triangleCoords,
  strokeColor: '#FF0000',
  strokeOpacity: 0.8,
  strokeWeight: 2,
  fillColor: '#FF0000',
  fillOpacity: 0.35
  });
  bermudaTriangle.setMap(document.map);
  </code></pre>
  
  <p>Suggestions? Is there a code technique out there that will take my giant array and then remove the interior points that appear to be the cause of this distortion?</p>
  
  <p>EDIT: Wondering about a different approach, does anyone know of a way to remove the interior lines that creating the bizarre trapezoid thing so that the zipcode polygon can fill in properly? I know I can make them transparent, but that doesn't stop the distortion of the polygon. Also simply managing it as a few polygons that I populate won't work as this program needs to be able to handle up to 200 zip codes worth of coordinates at a time.</p>