2011-09-27 68 views
-1

我有腳本(一)這是在我已經去這個功能一個javascript腳本:訪問返回的JavaScript變量在另一個腳本

function csf_viewport_bounds() { 
    var bounds = map.getBounds(); 
    var ne = bounds.getNorthEast(); 
    var sw = bounds.getSouthWest(); 

    var maxLat = ne.lat(); 
    var maxLong = ne.lng(); 
    var minLat = sw.lat(); 
    var minLong = sw.lng(); 

    var the_maps_bounds = [maxLat, maxLong, minLat, minLong]; 

    return(the_maps_bounds); 
} 

我也得到了jQuery腳本(B)。它有一個行(a)中調用函數:

google.maps.event.addListener(map, 'tilesloaded', csf_viewport_bounds); 

我如何可以訪問由返回什麼(一),the_maps_bounds,在腳本(B)?

謝謝。

回答

1

我假定你想要做的事tilesloaded後,涉及the_maps_bounds在這種情況下,你會做這樣的事情:

google.maps.event.addListener(map, 'tilesloaded', function() { 
    // This code will only execute after event `tilesloaded` happens 

    var the_maps_bounds = csf_viewport_bounds() 

    // now do something with the bounds 
    // ... 
}); 
+0

謝謝@mmcnickle。這很好。 – Laxmidi

0

更改腳本(二):

var bounds = csf_viewport_bounds(); 
google.maps.event.addListener(map, 'tilesloaded', bounds); 
// csf_viewport_bounds() return saved as local variable bounds. 
1

只需調用該函數第二次,因爲它不使用任何參數,並把結果分配給一個變量。

var myStuff = csf_viewport_bounds()