Getting the coordinates of a click in OpenLayers Map
06
Apr
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Getting the coordinates of a click in OpenLayers Map</title> <script src="http://openlayers.org/api/OpenLayers.js"></script> <script type="text/javascript"> function init(){ map = new OpenLayers.Map('map'); base_layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} ); map.addLayer(base_layer); map.setCenter(new OpenLayers.LonLat(79.8333,6.9167),7); map.events.register('click', map, handleMapClick); } function handleMapClick(evt) { var lonlat = map.getLonLatFromViewPortPx(evt.xy); alert("latitude : " + lonlat.lat + ", longitude : " + latitude); } </script> </head> <body onLoad="init()"> </body> </html>
1 Comment
Posted by Rajitha on April 6, 2013 in Geo Programming, JavaScript
Tags: openlayers
One response to “Getting the coordinates of a click in OpenLayers Map”