在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.