小编Nic*_*ick的帖子

将ID添加到谷歌地图标记

我有一个脚本循环并一次添加一个标记.

我试图让当前标记有一个信息窗口,并且一次只有一个地图上有5个标记(4个没有信息窗口,1个有)

如何为每个标记添加一个id,以便我可以根据需要删除和关闭信息窗口.

这是我用来设置标记的功能:

function codeAddress(address, contentString) {

var infowindow = new google.maps.InfoWindow({
  content: contentString
});

if (geocoder) {

  geocoder.geocode( { 'address': address}, function(results, status) {

    if (status == google.maps.GeocoderStatus.OK) {

        map.setCenter(results[0].geometry.location);

       var marker = new google.maps.Marker({
          map: map, 
          position: results[0].geometry.location
       });

       infowindow.open(map,marker);

      } else {
       alert("Geocode was not successful for the following reason: " + status);
      }
    });
  }
Run Code Online (Sandbox Code Playgroud)

}

javascript google-maps

76
推荐指数
2
解决办法
10万
查看次数

标签 统计

google-maps ×1

javascript ×1