用于infoWindow.close的mouseout在javascript中无法在Google Maps v3上运行

时间:2013-10-20 00:37:13

标签: javascript google-maps-api-3 infowindow

我在'mouseover'上有一个事件监听器可以工作并在infoWindow中显示正确的文本,但是这些infoWindow永远不会消失,除非你按下x。我希望它们在用户移开鼠标后消失。以下是代码。

谢谢!

iPark.makeMarker = function (lat, long, street, location, description ) {
  var myLatlng = new google.maps.LatLng(lat, long)
  var marker = new google.maps.Marker({
    position: myLatlng,
    title: 'Click to Zoom'
  });
  marker.setMap(this.map)

  google.maps.event.addListener(marker, 'click', function() {
    iPark.map.setZoom(18);
    iPark.map.setCenter(marker.getPosition());
    google.maps.event.addListener(marker, 'click', function() {
      iPark.map.setZoom(13)
      iPark.map.setCenter(37.7833, -122.4167)
    })
  });

  google.maps.event.addListener(marker, 'mouseover', function() {
    iPark.infoWindow(street).open(iPark.map, marker)
  });
  google.maps.event.addListener(marker, 'mouseout', function() {
    console.log("hello")
    iPark.closeinfoWindow
  });
}

iPark.infoWindow = function(street){
  return new google.maps.InfoWindow({
    content: String(street)
})

iPark.closeinfoWindow = InfoWindow.close()

};

2 个答案:

答案 0 :(得分:4)

将infoWindow存储为标记的属性:

google.maps.event.addListener(marker, 'mouseover', function() {
    if(!this.get('iw'))this.set('iw',iPark.infoWindow(street));
    this.get('iw').open(iPark.map, this);
  });

然后您将能够在以后访问它:

google.maps.event.addListener(marker, 'mouseout', function() {
    this.get('iw').close();
  });

答案 1 :(得分:0)

这看起来不对。

  google.maps.event.addListener(marker, 'mouseout', function() {
    console.log("hello")
    iPark.closeinfoWindow
  });

这可能效果更好(未经测试,基于报告的工作“mouseout”功能):

  google.maps.event.addListener(marker, 'mouseout', function() {
    iPark.infoWindow(street).close();

  });