以下代码将返回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格式?
请建议我!
答案 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 );