好久好久没写,,百度API逆地址解析以及删除指定marker
2021-03-27 05:24
标签:百度地图api poi ati function title doc cal 地图展示 覆盖 百度地图Api中 除覆盖物有两个方法:map.removeOverlay()或者 map.clearOverlays(),其中 clearOverlays()方法一次移除所有的覆盖物 最近项目一期上线,同时自己搬了新家 新的开始,安逸了,又不想奋斗了,哎 好好学习吧 好久好久没写,,百度API逆地址解析以及删除指定marker 标签:百度地图api poi ati function title doc cal 地图展示 覆盖 原文地址:https://www.cnblogs.com/yuwen1995/p/9361786.html
removeOverlay()一次移除一个指定覆盖物html>
head>
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
style type="text/css">
body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";font-size:14px;}
#allmap {width:100%;height:500px;}
style>
script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=AE01cf80f7e34194eb200a42443ed923">script>
title>逆地址解析title>
head>
body>
div id="allmap">div>
p >点击地图展示详细地址:span id="text" style="color: red;">span>p>
button onclick="oneDell(1)">删除第一个markerbutton>
button onclick="oneDell(3)">删除第三个markerbutton>
body>
html>
script type="text/javascript">
// 百度地图API功能
var text = document .getElementById ("text");
var markerArr = [];
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
map.centerAndZoom(point,12);
map.enableScrollWheelZoom(true);
var geoc = new BMap.Geocoder();
var index = 0
map.addEventListener("click", function(e){
var pt = e.point;
geoc.getLocation(pt, function(rs){
var addComp = rs.addressComponents;
text.innerHTML = addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber;
alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
});
var marker = new BMap.Marker(pt); // 创建标注
index = ++index
marker[‘id‘] = index;
markerArr.push(marker);
map.addOverlay(marker);
});
function oneDell(data){
for (var i = 0; i this.markerArr.length; i++) {
console.log(markerArr[i].id)
if (markerArr[i].id== data) {
map.removeOverlay(markerArr[i])
}
}
}
script>
文章标题:好久好久没写,,百度API逆地址解析以及删除指定marker
文章链接:http://soscw.com/index.php/essay/68433.html