-1

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

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

单击地图时如何准确获取纬度和经度什么是经度和纬度的确切格式?

请给我建议!

4

1 回答 1

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 );
于 2013-06-17T11:53:19.333 回答