Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want map coordinates as mouse over effect in OpenLayers. I am using the following code, however it is showing pixel coordinates:"mousemove", map, function(e) {      
    var position = + e.xy.y;
    OpenLayers.Util.getElement("tooltip").innerHTML = position 

thank you

share|improve this question
wow 7k views and only 4 up votes? – Below the Radar Feb 19 '14 at 16:18
up vote 10 down vote accepted

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

See also openlayers FAQ.

share|improve this answer

To add to simo's answer... here's an example:"mousemove", map, function (e) {
    var position =;
    OpenLayers.Util.getElement("tooltip").innerHTML = "<label>Latitude: " + + "</label><br/><label>Longitude: " + position.lon + "</label>";

You may need to transform from Mercator to Geographic as i did... if so:

var position = OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
share|improve this answer

As of Openlayers 2.12 the following approach works for accessing the coordinates from hovering:"mousemove", map, function (e) {            
var point = map.getLonLatFromPixel( )     
share|improve this answer

In Openlayers 2.13, you can do it like:

    new OpenLayers.Control.MousePosition({
        prefix: 'Coords: ',
        separator: ' | ',
        numDigits: 2,
        emptyString: 'Mouse not over map'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.