[OSM-dev] OpenLayers problem with latitude and longitude placement

Ulf Lamping ulf.lamping at googlemail.com
Sun Dec 7 14:14:35 GMT 2008

Maarten Deen schrieb:
> Are there any OpenLayers experts here?
> I'm trying to draw lines on a map using plain latitude and longitude 
> coordinates. So that I can use (0,0) for the equator and (0, 51) for some point 
> on the Greenwich meridian in England.
> But I can't find out how to do it.
> I have an example at <http://www.maasluip.nl/ebt/test.html>
> I make the lines in a loop at line 52. I almost thought "nice, it's degrees * 
> 111320", but that doesn't add up at higher latitudes.
> I understood the maxExtent in the projection to be the way to control this, but 
> apparently it isn't (as I have the map created with maxExtent: new 
> OpenLayers.Bounds(-180,-90,180,90))
> Any ideas?

No expert here, but I'm currently playing around with OSM myself.

I guess it's better to use the LonLat.transform function.

Maybe something like (quick hack):

             for (var p=0; p <= 50; p++)
                var pointList = [];
			   var lonLat0 = new OpenLayers.LonLat(0, 
p).transform(map.displayProjection,  map.projection);
			   var lonLat1 = new OpenLayers.LonLat(1, 
p).transform(map.displayProjection,  map.projection);

                newPoint = new OpenLayers.Geometry.Point(lonLat0.lon, 
                newPoint = new OpenLayers.Geometry.Point(lonLat1.lon, 

                var lineFeature = new OpenLayers.Feature.Vector(
                    new OpenLayers.Geometry.LineString(pointList));


Please let me know, if this is the correct solution.

I may need it later myself ...

Regards, ULFL

More information about the dev mailing list