寻找纬度和; Openstreetmap中的经度

时间:2013-06-13 15:09:57

标签: javascript map latitude-longitude openstreetmap

以下代码将返回lat& lon值,当我点击地图上的任何位置时。结果是lon=8931183.8958044,lat=1456094.8596215

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

如何获得lat&完全在点击地图时,是什么是lat和lon的extact格式?

请建议我!

1 个答案:

答案 0 :(得分:1)

找到解决方案:

  //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 );