OpenLayer coordinate system

I am trying to understand the coordinate system used by OpenLayers.

Leicester, UK, approx.

Latitude: 52.63973017532399 Longitude: -1.142578125 

But to display the same location using OpenLayers I have to use:

 Latitude: 6915601.9146245 Longitude: -125089.1967713 

eg:

 var center = new OpenLayers.LonLat(-125089.1967713, 6915601.9146245); var map = new OpenLayers.Map("demoMap"); map.addLayer(new OpenLayers.Layer.OSM()); map.setCenter(center, 12); 

This is clearly not the latitude-longitude coordinates, is there any kind of transformation that I need to consider?

Working example: http://craig-russell.co.uk/demos/openlayers/so_map.html

+8
javascript geolocation geocoding openlayers
source share
2 answers

Looks like I need to map coordinate systems. This is done using the transform() function:

 var coor_from = new OpenLayers.Projection("EPSG:4326"); var coor_to = new OpenLayers.Projection("EPSG:900913"); var center = new OpenLayers.LonLat(-1.142578125, 52.63973017532399); var map = new OpenLayers.Map("demoMap"); center.transform(coor_from, coor_to); map.addLayer(new OpenLayers.Layer.OSM()); map.setCenter(center, 12); 
+7
source share

Now you can do:

 var map = new OpenLayers.Map("demoMap"); var p = map.getView().getProjection(); var cord = ol.proj.fromLonLat([longitude, latitude], p); 
0
source share

All Articles