I have the following code. How to convert lonlat value to GPS used values in degrees?
UPDATE: I’m not sure that I use correct vocabulary, but currently lonlat is equal to something like this ‘2698.98978 1232.8998’. I want to conver to degrees, e.g. ‘41.2987 2.1989’.
lonlat is a variable. Please see in the code.
<html>
<head>
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
function init(){
map = new OpenLayers.Map('map');
base_layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
map.addLayer(base_layer);
map.zoomToMaxExtent();
map.events.register('click', map, handleMapClick);
}
function handleMapClick(evt)
{
var lonlat = map.getLonLatFromViewPortPx(evt.xy);
// use lonlat
alert(lonlat);
}
</script>
</head>
<body onload="init()">
Hello Map.<br />
<div id="map"></div>
</body>
</html>
You shouldn’t use the
getLonLatFromViewPortPxbut thegetLonLatFromPixelmethod like this:This will give you the correct coordinates without any transforms.