This is the most simplest way to add a drawing manager on the Google maps to draw polygon, circle, rectangle and etc by user.
code:
<
Create a global array which will contains your polygons
var polygons = [];
Then, fill your array in polygoncomplete
event :
google.maps.event.addDomListener(drawingManager, 'polygoncomplete', function(polygon) {
polygons.push(polygon);
In order to let the users the possibility to edit polgons after creation, you have to call setEditable
at the end of your polygonComplete
event
polygon.setEditable(true);
if you need to read all the lat/lng of polygon's vertices, you can use this sample of code :
var polygonBounds = polygon.getPath();
var coordinates = [];
for(var i = 0 ; i < polygonBounds.length ; i++)
{
coordinates.push(polygonBounds.getAt(i).lat(), polygonBounds.getAt(i).lng());
}