I want to save my polygon which user draws it into the strings like:
"SRID=4326;GEOMETRYCOLLECTION(POLYGON((......)))"
Is there anyway to do it ? I don't want to use encodeString from google API
thanks
I want to save my polygon which user draws it into the strings like:
"SRID=4326;GEOMETRYCOLLECTION(POLYGON((......)))"
Is there anyway to do it ? I don't want to use encodeString from google API
thanks
I found this solution and hope this also can help anybody out there with the same problem as mine.
Convert Google Maps Polygon (API V3) to Well Known Text (WKT) Geometry Expression
function GMapPolygonToWKT(poly) {
// Start the Polygon Well Known Text (WKT) expression
wkt = "SRID=4326;GEOMETRYCOLLECTION(POLYGON(";
var paths = poly.getPaths();
for(var i=0; i<paths.getLength(); i++) {
var path = paths.getAt(i);
// Open a ring grouping in the Polygon Well Known Text
wkt += "(";
for(var j=0; j<path.getLength(); j++) {
// setCenteradd each vertice and anticipate another vertice (trailing comma)
wkt += path.getAt(j).lng().toString()
+ " "
+ path.getAt(j).lat().toString()
+",";
}
// Also close the ring grouping and anticipate another ring (trailing comma)
wkt += path.getAt(0).lng().toString()
+ " "
+ path.getAt(0).lat().toString()
+ "),";
}
// resolve the last trailing "," and close the Polygon
wkt = wkt.substring(0, wkt.length - 1) + "))";
return wkt;
}
This is a valid string for GeoDjango postgis database.