2014-09-20 92 views
0

我試圖讓getBounds()工作。使getBounds()在外部函數中工作

當我有這樣的代碼:

google.maps.event.addListener(map, 'bounds_changed', createMarkerButton(marker,map)); 

function createMarkerButton(marker,map) { 

    alert(map.getBounds()); 
    ...... 

    } 

我得到一個錯誤,說getBounds()是不確定的。

但是,如果我這樣做

google.maps.event.addListener(map, 'bounds_changed', function(){ 

    alert(map.getBounds()); 

}); 

它完美的罰款。但是,我需要在createMarkerButton函數中工作。我該怎麼做?

回答

1

你的第一個代碼傳遞的是返回值createMarkerButton而不是函數本身。

試試這個:

google.maps.event.addListener(map, 'bounds_changed', function(){createMarkerButton(marker,map)});