Google 再次单击时地图标记发生变化 - 已附加 Fidde

Google Map Marker change when reclick again - Fidde attached

这是我的fiddle。 http://jsfiddle.net/tp2f74sz/

基本上我想要实现的是当我点击它时它变成绿色,但是当我重新点击时我想再次将它变回黑色。现在它改变了当我点击关闭图标

请帮忙

谢谢

    var infowindow = new google.maps.InfoWindow({
        
       id: this.id,
        content:this.html,
     pixelOffset: new google.maps.Size(0,-30),
        position:this.getPosition({pixelOffset: new google.maps.Size(500,0)})
        
        
      });
          
    

      var markerrr = new google.maps.Marker({
  position: location,
  map: map,
  icon: 'https://www.google.com/mapfiles/marker_green.png'
});
      
      
      google.maps.event.addListenerOnce(infowindow, 'closeclick', function(){
        markers[this.id].setVisible(true);
       markers[this.id].setIcon('https://www.google.com/mapfiles/marker_black.png');
        
      });
      
      this.setVisible(true);

      infowindow.open(map);
      this.setIcon('https://www.google.com/mapfiles/marker_green.png');
    });
  }

click 侦听器中,检查显示的是哪个图标,然后使用 .setIcon() 将其切换到另一个:http://jsfiddle.net/7zqde3kn/

google.maps.event.addListener(markers[i], 'click', function() {
  if (this.icon.includes('black')) {
    this.setIcon('https://www.google.com/mapfiles/marker_green.png');
  } else {
    this.setIcon('https://www.google.com/mapfiles/marker_black.png');
  }

  ...
}