title: Google Maps Drawing Iterate all shapes on overlay
body: <p>I have been toying around with Google Maps Drawing tools v3.  If a user creates a new polygon, I used this example to be able to track the location of the polygons:</p>
  
  <p><a href="https://stackoverflow.com/questions/14948337/getpaths-polygons-google-maps-api">getpaths() polygons google maps api</a></p>
  
  <p>Code:</p>
  
  <p>var polygons = [];</p>
  
  <pre><code>       google.maps.event.addDomListener(drawingManager, 'polygoncomplete', function (polygon) {
             polygons.push(polygon);
             console.log("polygon complete");
         });
  
         google.maps.event.addDomListener(savebutton, 'click', function () {
             document.getElementById("savedatapolygon").value = "";
             console.log(polygons.length);
             for (var i = 0; i &lt; polygons.length; i++) {
                 var polygonBounds = polygons[i].getPath();
                 // Iterate over the polygonBounds vertices.
                 var PolyNum = i
                 console.log(PolyNum);
                 polygonBounds.forEach(function (xy, i) {
                     console.log('Coordinate: ' + PolyNum + ':' + i + '&lt;br&gt;' + xy.lat() + ',' + xy.lng());
                 });
             }
         });
  </code></pre>
  
  <p>This is fine for when a user creates a Polygon, but what if they delete the Polygon?  The data is still stored in the array.  I can't seem to find a method to either track which array was deleted or have it iterate through all shapes at the end when the user clicks save.  Looking through the console, I can see that there might be a unique id assigned to each shape called __gm_id:, but i'm not sure if this would be the best way to track it.</p>
  
  <p>The other strange thing is that when you edit a shape, those changes are somehow getting updated to the polygon array even though there is nothing in the code stating that it should.</p>