2

我的一個應用程序在Google地圖上顯示多個位置標記。如何在短時間後顯示InfoWindow?如何在Gmap V3稍微延遲後加載InfoWindow?

這裏是我的腳本:

google.maps.event.addListener(marker, 'mouseover', onMarkerClick); 

//create a function that will open an InfoWindow for a marker mouseover 
var onMarkerClick = function() { 
    var marker = this; 
    var latLng = marker.getPosition(); 
    infowindow.setContent(
     '<h3>Marker position is:</h3>' + latLng.lat() + ', ' + latLng.lng()); 
    infowindow.open(map, marker); 
}; 

回答

5

setTimeout應該做你想要什麼。該數字是毫秒延遲。

setTimeout(function() { infowindow.open(map, marker) }, 500); 
+1

請記住,當觸發新的mouseover事件時,您還需要清除設置的timouts。 更多資訊可在此答案中找到。 http://stackoverflow.com/questions/5786646/stop-function-that-run-with-settimeout – Philip