Finding out the latitude/longitude coordinates of the click on a map
HTML
<script src="https://www.amcharts.com/lib/3/ammap.js"></script>
<script src="https://www.amcharts.com/lib/3/maps/js/usaLow.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<div id="chartdiv"></div>
<div id="maplog"></div>
CSS
body {
font-size: 12px;
font-family: Verdana;
padding: 10px;
}
#chartdiv {
width : 70%;
height : 300px;
float: left;
}
#maplog {
width : 26%;
height : 300px;
float: left;
overflow: auto;
margin-left: 10px;
border-left: 1px solid #bbb;
font-size: 10px;
}
JavaScript
var map = AmCharts.makeChart("chartdiv", {
"type": "map",
"theme": "none",
"pathToImages": "http://www.amcharts.com/lib/3/images/",
"dataProvider": {
"map": "usaLow",
"getAreasFromMap": true
},
"areasSettings": {
"autoZoom": true,
"selectedColor": "#CC0000"
}
});
// define an event to catch all click events on th emap
map.addListener("click", function (event) {
// find out the coordinates of under mouse cursor
var info = event.chart.getDevInfo();
console.log(info);
// print out dev info
var log = document.getElementById('maplog');
log.innerHTML = "click (lat: "+ info.latitude + " long: "+ info.longitude + ")<br />" + log.innerHTML;
});