高德地图-点击事件
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>异步加载</title> 6 <script type="text/javascript"> 7 var map=null; 8 var marker=null; 9 function eventHandler(e){ 10 var lnglat = e.lnglat; 11 //alert(lnglat.lng+":"+lnglat.lat); //经度 12 if(marker!=null){ 13 marker.setPosition(lnglat); 14 }else{ 15 marker = new AMap.Marker({ 16 map:map, 17 position:lnglat, 18 title:"商店", 19 icon:"http://webapi.amap.com/images/0.png", 20 offset:new AMap.Pixel(-10,-34) 21 }) 22 marker.setMap(map); 23 } 24 } 25 function init() { 26 var d = new Date(); 27 map = new AMap.Map(mapDiv, { 28 view:new AMap.View2D({ 29 center: new AMap.LngLat(116.39, 39.9), 30 zoom:15 31 }) 32 }); 33 var listener = AMap.event.addListener(map,"click",eventHandler); 34 } 35 function loadScript() { 36 var script = document.createElement("script"); 37 script.type = "text/javascript"; 38 script.src = "http://webapi.amap.com/maps?v=1.3&key=973ff4275eaf1fb1ba1292a967ba116b&callback=init"; 39 document.body.appendChild(script); 40 } 41 window.onload = loadScript; 42 </script> 43 </head> 44 <body> 45 <input type="button" value="aaa"/> 46 <div id="mapDiv" style="width:800px; height:600px"></div> 47 48 </body> 49 </html>