web前端页面中异步使用百度地图API
<div id="allmap"></div>
1 //百度地图API功能 2 function loadJScript() { 3 var script = document.createElement("script"); 4 script.type = "text/javascript"; 5 script.src = "http://api.map.baidu.com/api?v=2.0&ak=8ni9BKv4NW6uDu5LUrRKCuCGp4RREX3g&callback=init"; 6 document.body.appendChild(script); 7 } 8 9 function init() { 10 var map = new BMap.Map("allmap"); // 创建Map实例 11 var point = new BMap.Point(116.293088,39.830886); // 创建点坐标 12 map.centerAndZoom(point, 18); 13 map.enableScrollWheelZoom(); //启用滚轮放大缩小 14 var marker = new BMap.Marker(point); 15 map.addOverlay(marker); // 将标注添加到地图中 16 marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画 17 18 } 19 window.onload = loadJScript; //异步加载地图