This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

How to get longitude and latitude from bound?

0

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

Is this the correct lat & lon? because I see that the Lat & Lon comes in 2 digit (0-90) before can some one help me in converting the values?

asked 13 Jun '13, 16:06

gayathri's gravatar image

gayathri
11223
accept rate: 0%

edited 14 Jun '13, 05:42

2

This is an OpenLayers question not OpenStreetMap try GIS Stack Exchange, read a bit about projections, and this blog post might be useful http://macwright.org/2012/01/12/openlayers.html.

(14 Jun '13, 15:14) SK53 ♦

One Answer:

0

lonlat.lon, lonlat.lat

answered 13 Jun '13, 19:42

yvecai's gravatar image

yvecai
1.5k1226
accept rate: 9%

Is this the correct lat & lon? because I see that the Lat & Lon comes in 2 digit (0-90) before can some one help me in converting the values?

(14 Jun '13, 05:42) gayathri

I guess you have read this https://wiki.openstreetmap.org/wiki/Bounding_box and noticed that it uses degrees and fractions in decimal format NOT degrees Minutes and Seconds so 45.5 deg= 45,30,00 DMS. If that does not help what lat lon were you expecting to get back from your code. Could you set it up so you know the result beforehand as a test?

(14 Jun '13, 19:46) andy mackey
1

thank for u kindly reply.... i got answer

(15 Jun '13, 07:26) gayathri
var fromProjection = new OpenLayers.Projection("EPSG:4326");  
var toProjection   = new OpenLayers.Projection("EPSG:900913");
var mapbounds = map.getExtent(); // to getting the bounds
var bound = mapbounds.transform(toProjection, fromProjection ); // converting the bounds to left, right, bottom & top values.
(15 Jun '13, 07:29) gayathri

Source code available on GitHub .