[OpenLayers-Users] What is the meaning of the result of getLonLatFromPixel ?

Alex Dean alex at crackpot.org
Wed Sep 1 15:31:08 EDT 2010


On Sep 1, 2010, at 2:20 PM, huit_six wrote:

>
> I tried that sort of conversion :
>                var point = map.getLonLatFromPixel(position);
> 		locDisp.innerHTML = (point.lat / 40000000 * 360 ).toFixed(4)+ ', ' +
> (point.lon / 40065035.535 * 180).toFixed(4);
> which seem to give results  in the good ranges.
> But is it really the good way of conversion ? And why the latitude and
> longitude would be given in meters ? Isn't it weird ? Have I missed
> something ?

I couldn't find OpenLayers.Layer.OSM in the API docs, but the  
coordinates on your sample look like they're in 'spherical mercator',  
which is common for WMS providers like Google, Yahoo, etc.  http://docs.openlayers.org/library/spherical_mercator.html 
  says that OSM is indeed spherical mercator.

So, I think you're getting x & y values in the coordinate system of  
your base layer.  I think the values are actually a number of meters  
north & east of 0.  You can translate that to EPSG:4326 (lat/lon)  
using a function described in this page
http://dev.openlayers.org/releases/OpenLayers-2.9.1/doc/apidocs/files/OpenLayers/Layer/SphericalMercator-js.html

Also take a look at the re-projection examples on the  
spherical_mercator.html page I linked to above.

alex



More information about the Users mailing list