Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

The below code will return the lat & lon values, when i click any where on the map. The result is lon=8931183.8958044,lat=1456094.8596215

map.events.register('click', map, handleMapClick);
function handleMapClick(e)
{
var lonlat = map.getLonLatFromViewPortPx(e.xy);
alert(lonlat);
}

how to get the lat & lon exactly when clicking on the map what is the extact format for lat and lon?

Kindly advice me!

share|improve this question
1  
Does this actually have anything to do with Google Maps? If not you should remove that tag. –  geocodezip Jun 13 '13 at 20:44
2  
Does this actually have anything to do with OpenStreetMap? If not you should remove that tag/title. This is an OpenLayers issue. –  scai Jun 15 '13 at 12:52
    
I am using openstreet Map and I am getting the above issue.. its an openstreet issue!!!! –  TomPHP Jun 15 '13 at 13:24

1 Answer 1

up vote 0 down vote accepted

Found the solution:

  //defining the projection
    var fromProjection = new OpenLayers.Projection("EPSG:4326");   
    var toProjection   = new OpenLayers.Projection("EPSG:900913");

    //getting the bounds
    var mapbounds = map.getExtent();

    //transform bounds to lat& long
    var val = mapbounds.transform(toProjection, fromProjection );
share|improve this answer

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.