문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top