2017-04-12 67 views
1

在这个项目中,我有两种不同的标记,我使用下面的代码在地图上显示。infowindow隐藏在悬停标记

for (i = 0; i < beaches.length; i++) { 
    marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(beaches[i][1], beaches[i][2]), 
     map: mapSingle, 
     icon: icons[beaches[i][3]].icon 
    }); 
    var infowindow = new google.maps.InfoWindow(); 
    var content = beaches[i][0]; 
    google.maps.event.addListener(marker,'mouseover', (function(marker,content,infowindow){ 
     return function() { 
      infowindow.setContent(content); 
      infowindow.open(mapSingle,this); 
     }; 
    })(marker,content,infowindow)); 
    markers.push(marker); 
} 

现在有了新的要求,我必须放置一种可拖动的新型标记。所以,当我做悬停在此拖动的标记我有这样的代码

com_current = new google.maps.Marker({ 
    map: mapSingle, 
    draggable: true, 
    icon: com_Image, 
    animation: google.maps.Animation.DROP, 
    position: {lat: parseFloat('20.5937'), lng: parseFloat('78.9629')}, 
}); 
google.maps.event.addListener(com_current, 'mouseover', function() { 
    var info = infowindow.getContent(); 
    infowindow.setContent('show the position of the marker'); 
    infowindow.open(mapSingle, this); 
}); 

现在,我得到的问题是,它的信息窗口变得开放这是确定其他已经打开信息窗口皮的,但一些,反之亦然。我怎样才能让其他已经打开的标记显示,即使我悬停在这个可拖动的标记。

回答

1

因为您正在使用用于不可拖动标记的相同信息窗口对象。所以请尝试使用下面的代码。

com_current = new google.maps.Marker({ 
    map: mapSingle, 
    draggable: true, 
    icon: com_Image, 
    animation: google.maps.Animation.DROP, 
    position: {lat: parseFloat('20.5937'), lng: parseFloat('78.9629')}, 
}); 
infoWindowForDraggableMarker = new google.maps.InfoWindow(); 
google.maps.event.addListener(com_current, 'mouseover', function() { 
    infoWindowForDraggableMarker.setContent('show the position of the marker'); 
    infoWindowForDraggableMarker.open(mapSingle, this); 
}); 

编辑

在您要创建信息窗口代码中的第一个块对象下,像权,变更。

var infowindow = new google.maps.InfoWindow(); 
for (i = 0; i < beaches.length; i++) { 
    marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(beaches[i][1], beaches[i][2]), 
     map: mapSingle, 
     icon: icons[beaches[i][3]].icon 
    }); 
    var content = beaches[i][0]; 
    google.maps.event.addListener(marker,'mouseover', (function(marker,content,infowindow){ 
      return function() { 
      infowindow.setContent(content); 
      infowindow.open(mapSingle,this); 
     }; 
    })(marker,content,infowindow)); 
    markers.push(marker); 
} 

并且对于可拖动标记也使用相同的对象,如下所示。

com_current = new google.maps.Marker({ 
    map: mapSingle, 
    draggable: true, 
    icon: com_Image, 
    animation: google.maps.Animation.DROP, 
    position: {lat: parseFloat('20.5937'), lng: parseFloat('78.9629')}, 
}); 
google.maps.event.addListener(com_current, 'mouseover', function() { 
    infowindow.setContent('show the position of the marker'); 
    infowindow.open(mapSingle, this); 
}); 
+0

谢谢@Naveen。如果我将鼠标悬停在一个标记上,我如何隐藏其他打开的infowindow。你能帮忙吗 – sanin

+0

只需使用一个信息窗口对象。那么地图上只会有一个信息窗口。 –

+0

这就是我在我的问题中所做的。但是,它不工作 – sanin