I am trying to get the latlng coordinates of both a polyline and a polygon. After I finish drawing any object, I would like to save latlng in the database, but for now I'm just trying to show latlng in a text box. I made it easy enough for markers, rectangles and circles, but the terminology for polylines and polygons puzzles me. When I finish drawing, I use addDomListener (drawingManager, "polygoncomplete", ... for polynomials, and then iterate over all the polygons that I drew. For each polygon, I then repeat its array of coordinates. I searched this forum database and tried an example Bermuda Triangle on Google Docs Page:
An Example of Bermuda
I read the documentation many times and simply could not see what was missing. Any help is appreciated.
var polygons = [];
google.maps.event.addDomListener(drawingManager, 'polygoncomplete', function(polygon) {
polygons.push(polygon);
});
google.maps.event.addDomListener(savebutton, 'click', function() {
document.getElementById("savedatapolygon").value = "";
for (var i = 0; i < polygons.length; i++) {
var polygonBounds = polygons[i].getPath();
var xy;
for (var i = 0; i < polygonBounds.length; i++) {
xy = polygonBounds.getAt(i);
contentString += '<br>' + 'Coordinate: ' + i + '<br>' + xy.lat() +',' + xy.lng();
}
document.getElementById("savedatapolygon").value += "polygon(";
document.getElementById("savedatapolygon").value += contentString;
document.getElementById("savedatapolygon").value += ")";
}
});
source
share