0
votes

I'm using Openlayers 2.13 to draw polygons. I need to save the polygons in my database. I use the following code to retrieve a WKT (Well-know Text) format of the polygon: getGeometry().toString();

The WKT looks like this:

"POLYGON((2214109.1963538 -3576110.9131445,2150513.5888293 -3766897.7357178,2529641.249071 -3656828.4150024,2529641.249071 -3656828.4150024,2214109.1963538 -3576110.9131445))"

However, when I try to write that to the DB i get the following error:

24201: Latitude values must be between -90 and 90 degrees.

Why are the GPS coordinates from Openlayers so big?

I've tried changing the projection of the map, but to no avail.

1

1 Answers

1
votes

You are trying to insert into a latlon geometry column (as defined in your database) a geometry in another projection system.

You should reproject the geometry before transforming it to WKT. You need something like this:

var srcPrj = new OpenLayers.Projection('EPSG:3857'): //put your map projection here!
var trgPrj = new OpenLayers.Projection('EPSG:4326');
var geometry = feature.getGeometry();
geometry = geometry.transform(srcPrj, trgPrj);
var wkt = geometry.toString();