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'm have been searching for several hours and do not find a way to get mouse coordinates after a SelectFeature, which returns the feature by itself. I saw that this has been asked several times earlier, so I try again!

share|improve this question
I need an answer to this aswell. – netbrain Mar 27 '12 at 9:12

When you init the map add this control:

mapMousePosition = new OpenLayers.Control.MousePosition({
        displayProjection: new OpenLayers.Projection(displayProjection)

In your handler get lonLat like this:

 var lonLat = map.getLonLatFromPixel(
      new OpenLayers.Pixel(
share|improve this answer

You can get it with these ways:


or"click", map, function(e) { 
    var latlon = map.getLonLatFromViewPortPx(e.xy) ;


new OpenLayers.Control.SelectFeature(layer,{

            "featureselected": function(e) {       

i hope it helps you....

share|improve this answer
Aragon, I think he is asking for mouse coordinates (mostly to display Popup) and not map coordinates. What your answer telling is to get map coordinates. – Suraj Jul 1 '14 at 10:49

my strategy (very resource intensive) is to listen to mousemove and constantly saving x and y values in global variables.

var mouseLat, mouseLon;
function init(){
  ..."mousemove", map, function(e) {
    var position =;
    var lonlat = map.getLonLatFromPixel(position);
    var lonlatTransf = lonlat.transform(map.getProjectionObject(), proj4326);
    mouseLat =;
    mouseLon = lonlatTransf.lon;
    OpenLayers.Util.getElement("coords").innerHTML = "Lat: "+ mouseLat+" | Lon: "+mouseLon;

when the feature is selected, i access these values from inside onFeatureSelect(event)

share|improve this answer
To decrease resource consumption, use debounce/throttle techniques – ThomasG77 Nov 12 '14 at 23:07

Just as an addition to the answer of Laurentiu Turcu:

As I thought this is an interesting question I set up a jsfiddle which demonstrates how to show the popup at the last mousePosition when you select a feature:

so even if the question is 3 years old...perhaps someone can use this if he/she stumples across this question.

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.