How to convert Vector Layer coordinates into Map Latitude and Longitude in Openlayers.

Posted by Jenny on Stack Overflow See other posts from Stack Overflow or by Jenny
Published on 2010-04-08T16:37:41Z Indexed on 2010/04/09 12:03 UTC
Read the original article Hit count: 202

I'm pretty confused. I have a point:

x= -12669114.702301
y= 5561132.6760608

That I got from drawing a square on a vector layer with the DrawFeature controller.

The numbers seem...erm...awfull large, but they seem to work, because if I later draw a square with all the same points, it's in the same position, so I figure they have to be right.

The problem is when I try to convert this point to latitude and longitude.

I'm using:

map.getLonLatFromPixel(pointToPixel(points[0]));

Where points[0] is a geometry Point, and the pointToPixel function takes any point and turns it into a pixel (since the getLonLatFromPixel needs a pixel). It does this by simply taking the point's x, and making it the pixels x, and so on.

The latitude and longitude I get is on the order of:

lat: -54402718463.864
lng: -18771380.353223

This is very clearly wrong. I'm left really confused. I try projecting this object, using:

.transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());

But I don't really get it and am pretty sure I did it incorrectly, anyways.

My code is here: http://pastie.org/909644

I'm sort of at a loss. The coordinates seem consistent, because I can reuse them to get the same result...but they seem way larger than any of the examples I'm seeing on the openLayers website...

© Stack Overflow or respective owner

Related posts about openlayers

Related posts about latitude-longitude