首页 > 代码库 > 百度地图Api进阶教程-点击生成和拖动标注4.html
百度地图Api进阶教程-点击生成和拖动标注4.html
<!DOCTYPE html><html><head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>12.1</title> <script type="text/javascript"> var iscreatr = false; function initialize() { var map = new BMap.Map("container", { minZoom: 12, maxZoom: 25 }); map.centerAndZoom("成都", 13); map.enableScrollWheelZoom(true); map.addEventListener("click", function (e) { if (iscreatr == true) return; //---------------------------------------------遮盖物--------------------------------------------- iscreatr = true; var point = new BMap.Point(e.point.lng, e.point.lat); // 创建标注对象并添加到地图 var marker = new BMap.Marker(point); var lable = new BMap.Label("我是可以拖拽的", { offset: new BMap.Size(20, -10) }); marker.setLabel(lable); map.addOverlay(marker); marker.enableDragging(); //可拖拽 marker.addEventListener("dragend", function (e) { document.getElementById("r-result").innerHTML = e.point.lng + "," + e.point.lat; //打印拖动结束坐标 }); }); } function loadScript() { var script = document.createElement("script"); script.src = "http://api.map.baidu.com/api?v=1.4&callback=initialize"; document.body.appendChild(script); } window.onload = loadScript; </script></head><body> <div style="float: left; width: 100px;"> 1</div> <div id="container" style="width: 800px; height: 500px"> </div> <div id="r-result" style="float: left; width: 100px;"> 打印坐标</div> <div id="result"> </div></body></html>
百度地图Api进阶教程-点击生成和拖动标注4.html
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。