1

I need to get the coordinates of the click when the user clicks on any place on the base map. I have checked the answer to similar problem here: How do I get the coordinates of a click on vector feature/layer in OpenLayers?

But, I need the coordinates transformed to the projection system used by my map: that is EPSG:900913, Spherical Mercator Projection and passed to a html textbox.

How can I do that?

Amin
  • 13
  • 2

1 Answers1

2

You should use the OpenLayers.LonLat.transform() function.

If you want to transform between EPSG 4326 & EPSG:900913, Openlayers can do it for you.

If you want to transform between some other projections, then you will have to use the Proj4js library.

Include in your page:

<script src="http://proj4js.org/lib/proj4js-compressed.js"></script>

Then in your javascript

var lonlat = yourpoint.clone();
lonlat.transform(map.projection, <target projection>);

Note that transform() changes the actual object, so if you need the orignal object for something, remember to clone it.

Devdatta Tengshe
  • 41,311
  • 35
  • 139
  • 263