其他分享
首页 > 其他分享> > 百度地图多个点标注

百度地图多个点标注

作者:互联网

 var point = new Array(); //存放标注点经纬信息的数组
          var marker = new Array(); //存放标注点对象的数组
          var markArry = ["116.407718,39.913828", "116.237543,39.913828", "116.430715,39.933306"];
          for (var i = 0; i < markArry.length; i++) {
              var myIcon = new BMap.Icon("http://api.map.baidu.com/img/markers.png", new BMap.Size(23, 25), {
                  offset: new BMap.Size(10, 25), // 指定定位位置
                  imageOffset: new BMap.Size(0, 0 - i * 25) // 设置图片偏移
              });
              point[i] = new BMap.Point(markArry[i].split(',')[0], markArry[i].split(',')[1]);
              console.log(point[i])
              marker[i] = new BMap.Marker(point[i], { icon: myIcon });
              console.log(marker[i])
              map.addOverlay(marker[i]);
              marker[i].addEventListener("click", function () {
                  this.openInfoWindow(new window.BMap.InfoWindow("窗口信息"));
              });
          }

解决信息窗口只显示循环最后一个的方法

是把窗口的函数放到循环外面

 

标签:point,地图,var,BMap,marker,new,markArry,百度,标注
来源: https://blog.csdn.net/m0_49471668/article/details/121556922