Question

I am quite new to OpenLayers, and already stuck on my first problem. I am trying to convert "normal" coordinates, which I copied from Google Maps to OSM ones to center my map to a certain area. Now as far as i understood ist the "normal" coordinate system EPSG:4326 and the OSM one is EPSG:3857 or EPSG:900913, which is the same. so my Javascript code is:

map.setCenter(new OpenLayers.LonLat(53.537460, 9.953227).transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:3857")), 5);

But this centers to a total different location. what am I missing?

Was it helpful?

Solution

Google Maps and OSM show exactly the same position. Everything else would be odd.

However you are mixing up lat and lon. OpenLayers.LonLat() accepts first lon, then lat as the name already tells you. But you are passing lat first and then lon, which will result in a completely different position of course.

OTHER TIPS

Is your location in Steinwerder (Hamburger Hafen) or off the Horn of Africa? I assume the first so the Latitude would be 53 degree north and the longitude 9 degree west.

This should set your map in the right location.

map.setCenter(new OpenLayers.LonLat(9.953227,53.537460).transform('EPSG:4326', map.getProjectionObject()), 5);

You only need to know the input coordinate reference and use the getProjectObject function to get the target reference.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top