Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

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.