Finding coordinates of a point in OpenLayers

gis, openlayers

Solution

Handle click event on map Click handler. Here is one of many sample codes you can find in OpenLayers mailing list archives:

map.events.register('click', map, handleMapClick);

function handleMapClick(e)
{
   var lonlat = map.getLonLatFromViewPortPx(e.xy);
   // use lonlat

   // If you are using OpenStreetMap (etc) tiles and want to convert back 
   // to gps coords add the following line :-
   // lonlat.transform( map.projection,map.displayProjection);

   // Longitude = lonlat.lon
   // Latitude  = lonlat.lat
} 

Problem

How can one get the coordinates of a particular point on a map in OpenLayers?

Original source