在maps api v3上绘制一个多边形并将其保存到postgresql几何列

1.- User draw a polygon in a web app.

2.- When user click save i want to save the data in a postgresql DB.

I'm having trouble with the polygon coordinates...

POLYGON COORDINATES VALUES IN A TEXT FIELD, IT LOOK LIKE THIS:

(13.068776734357694, -65.50735473632812),(6.795535025719505, -62.123565673828125),(7.928674801364048, -70.78079223632812)

I GOT THEM WHEN THE USER DRAW ON MAP

google.maps.event.addListener(drawingManager,'polygoncomplete',function(polygon) {

// complete functions
var coordinates = (polygon.getPath().getArray());
$("#coordinates").val(coordinates);

});

SO FAR SO GOOD, when i passed those values in a form and try to save them in the DB i got this error:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[XX000]: Internal error: 7 ERROR: parse error - invalid geometry HINT: "(1" <-- parse error at position 2 within geometry' in

PHP

$stmt = $link->prepare("INSERT INTO industrias.industrias (rif,nombre,geom) VALUES (:rif,:nombre,:coor)");
$stmt->execute(array(':rif'=>$_POST["rif"],':nombre'=>$_POST["nombre_empresa"],':coor'=>$_POST["coordinates"]));

QUESTION 1:

There is any other function that get those coordinates in some other pattern that will fit into the column type geometry (Polygon,4326)?

QUESTION 2:

Can i use some postgis function in the SQL STATEMENT to make it work? something with WKT or something else?

I do a geo fencing module where i save lot of shapes in database. I don't save coordinated like that.

I use google encoding algorithem to encode the path of polygons and poly lines and then save the encoded string in databse.

https://developers.google.com/maps/documentation/javascript/examples/geometry-encodings

the circles can be saved as lat,lon and radius though.

this will be easy and stable solution in long run.

If you need coordinates, just decode them back using google api encoding functions available.

Update:

i cant show u the application as its against my company policy but some code clips to help you:

when finished drawing:

google.maps.event.addDomListener(drawingManager, 'polygoncomplete', function(polygon) {      
          drawingManager.setDrawingMode(null); // disable drawing mode
          CreateCourseRegionPoly(polygon);          
      });

I do below to save in database using rest service (notice encode uri, as some funny characters can appear in encoded):

function CreateCourseRegionPoly(poly){
var polypath= poly.getPath();
var encodeString = google.maps.geometry.encoding.encodePath(polypath); 
   $.ajax({
      url: '../RestApi/CreateRegion',
      type: 'POST',
      contentType: 'application/json',
      cache: false,
      dataType: 'json',          
      data: '{"CourseID":"'+ courseID +'","PolygonPath":"'+encodeURIComponent(encodeString)+'"}',
      error: function (jqXHR, textStatus, errorThrown) {
        alert("Messaging failed: " + errorThrown);
      },
       success: function (data) {
       //d oyour sucess bit here...
       }
    });
}