Openlayers获取鼠标点击时的经纬度
在Openlayers点击事件中,常常需要获取当前点击点的经纬度,可以用此方法获取:
map.events.register('click', map, function (e) { var pixel = new OpenLayers.Pixel(e.xy.x,e.xy.y); var lonlat = map.getLonLatFromPixel(pixel); lonlat.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326")); //由900913坐标系转为4326
alert(lonlat.lon+", "+lonlat.lat);
})
End.