2016-02-11 31 views
0

請參閱以下屏幕截圖。如何在Google地圖中關閉以前的infoWindow

screenshot

我的代碼是

function get(position, html, resultsMap){ 

    //alert(position); 
    var getDirection = new google.maps.InfoWindow({ 
     content: '', 
     position: position 
    }); 
    getDirection.close(); 
    getDirection.setContent(html); 
     getDirection.open(resultsMap); 
    } 

函數調用

get(position, html, resultsMap); 

所有這一切工作正常,除了上述問題。我想關閉以前的infoWindow並只顯示新的Infowindow,點擊另一個鏈接(所有鏈接都有相同的類)。如何解決。

+0

他們唯一能做的就是降低我的聲譽:) –

+1

我沒有downvote,但我認爲你應得的。請看一些更好的問題,並嘗試瞭解其中的差異。 – Trix

+0

[自動關閉InfoWindow在googlemap中]的可能重複(http://stackoverflow.com/questions/28138468/auto-close-infowindow-in-googlemap) – geocodezip

回答

0

爲什麼不重新使用您已經擁有的新位置的infoWindow?

HandleInfoWindow(self.places()[p], contentString, p); 
map.setCenter(marker.location); 


var HandleInfoWindow = function(place, content, index) { 
     var position = { 
     'lat': place.lat(), 
     'lng': place.lng() 
     }; 
     infoWindow.setContent(content); 
     infoWindow.setPosition(position); 
     infoWindow.open(map); 
}; 
// Closes infoWindow 
infoWindow.close(); 

是的,有讓這一切工作需要很多更多的代碼,但是這些部分將集中你的信息窗口,並允許它的重用,而不是創建誰知道有多少。

我已經爲您包括了密碼。

相關問題