Javascript 如何制作隐藏和显示infobubble标记的函数

Javascript 如何制作隐藏和显示infobubble标记的函数,javascript,function,google-maps,Javascript,Function,Google Maps,我需要一个复选框来获得一个函数来隐藏和显示一个标记或一组标记 出于某种原因idk(我是谷歌地图api新手)这个函数不适用于infobubbles,当我尝试使用infowindow时,它可以工作。。有什么帮助吗?谢谢 var map; function init() { var mapCenter = new google.maps.LatLng(-22.967956,-43.197397); map = new google.maps.Map(document.g

我需要一个复选框来获得一个函数来隐藏和显示一个标记或一组标记

出于某种原因idk(我是谷歌地图api新手)这个函数不适用于infobubbles,当我尝试使用infowindow时,它可以工作。。有什么帮助吗?谢谢

    var map;

  function init() {

    var mapCenter = new google.maps.LatLng(-22.967956,-43.197397);
    map = new google.maps.Map(document.getElementById('map'), {
      zoom: 14,
      center: mapCenter,
      streetViewControl: true,
      mapTypeControl: true,
      mapLabels:true,
      mapTypeId: google.maps.MapTypeId.HYBRID
    });

    var myLatLng = new google.maps.LatLng(-22.973878,-43.192564);
    var myLatLng1 = new google.maps.LatLng(-22.968373,-43.183176);

    var marker = new google.maps.Marker({
      map: map,
      position: myLatLng,
      title: 'marker'
     });

     var marker1 = new google.maps.Marker({
      map: map,
      position: myLatLng1,
      title: 'marker1'
     });

     infoBubble = new InfoBubble({
      maxWidth: 246,
      maxHeight: 350


    });

    infoBubble.addTab('home', contenthome);
    infoBubble.addTab('Info', content);
    infoBubble.addTab('Fase', contentString);

    google.maps.event.addListener(marker, 'click', infobut); 

    function infobut(event) {

             if (!infoBubble.isOpen()) {
        infoBubble.open(map, marker);          }
        }

    infoBubble1 = new InfoBubble({
       maxWidth: 246,
      maxHeight: 350

    });

    infoBubble1.addTab('home', contenthome);
    infoBubble1.addTab('Info', content);
    infoBubble1.addTab('Fase', contentString);

    google.maps.event.addListener(marker1, 'click', infobut1); 

    function infobut1(event) {

             if (!infoBubble1.isOpen()) {
        infoBubble1.open(map, marker1);         }
    }

    function hidemarker() {
            marker1.setVisible(false);
          }
还有按钮

       <input type="checkbox" onClick="hidemarker()" name="1qts" value="1 Quartos" class="botao2">

从您的代码中不清楚
init()函数在哪里完成。我把
}
放在
hidemarker()函数前面。问题是变量
marker1
不可见,应该将其设置为全局变量,就像变量
map
一样

要关闭信息气泡,只需调用方法
close()

var map;

var marker1;

function init() {
    ...
    marker1 = new google.maps.Marker({
        map: map,
        position: myLatLng1,
        title: 'marker1'
    });
    ...
}

function hidemarker() {
    infoBubble1.close();
    marker1.setVisible(false);
}

google.maps.event.addDomListener(window, 'load', init);