我試圖關閉像這樣marker.infowindow.close();
但那不工作。任何建議?如何在用戶點擊其他引腳時關閉以前的infowindow?
marker.infowindow = new google.maps.InfoWindow({
noSupress: true,
content: ''
});
marker.addListener('click', (function (marker, i) {
return function() {
var position = this.position;
property_id = locations[i].id;
lat = locations[i].lat;
lng = locations[i].lng;
name = locations[i].name;
address = locations[i].address;
default_image = locations[i].default_image;
$('.hightlight-'+property_id+' a').css('color', '#1996d5');
html = '<div class="markerBox">' + '<div class="default_image"><img src="storage/uploads/property' + property_id + "/" + default_image + '" alt="' + name + '"/></div>' + '<div class="content"><h2><a href="/property/' + property_id + '">' + name + '</a></h2><h4><span>Address: </span>' + address + '</h4>' + '</div></div>';
map.setCenter(marker.getPosition());
// Reset pin
for (var ix = 0; ix < markers.length; ix++) {
markers[ix].setIcon(searchPinImage);
}
map.setZoom(14);
marker.setIcon(activePinImage);
this.infowindow.setContent(html);
//this.infowindow.setPosition(position);
this.infowindow.open(map);
this.infowindow.setPosition(position);
google.maps.event.addListener(infowindow, 'closeclick', function() {
//marker.setIcon(searchPinImage);
});
這裏是我的小提琴:
http://jsfiddle.net/pGBZD/860/
您可以創建一個工作的jsfiddle或片段,它; S很難找到問題只是在這段代碼,方法是infowindow.close()https://開頭開發商。 google.com/maps/documentation/javascript/3.exp/reference#InfoWindow,它可能在您的代碼中存在其他問題 –
@VladuIonut http://jsfiddle.net/pGBZD/860/ – None
是否有某種原因你不想只將infowindow移動到新標記並更改其內容? –