OpenLayers 2 – How to Display Mouse Position as Tooltip

javascriptopenlayers-2

I want map coordinates as mouse over effect in OpenLayers. I am using the following code. However it is showing pixel coordinates:

    map.events.register("mousemove", map, function(e) {      
      var position = e.map.x + e.xy.y;
      OpenLayers.Util.getElement("tooltip").innerHTML = position 
    });

Best Answer

you can convert pixels to lat/long with the help of getLonLatFromPixel() function.

See also openlayers FAQ.

Related Question