Google maps api 3 setZoom在传递javascript变量时表现异常

Google maps api 3 setZoom在传递javascript变量时表现异常,google-maps-api-3,Google Maps Api 3,我正在尝试在单独的页面中创建指向地图的链接。当用户单击链接时,它将重定向到地图并显示与链接对应的地质多边形。然而,经过数小时的调试,我发现setZoom函数阻止了我这样做,我不知道为什么。如果单击“在地图上查看Tg”按钮,则会创建url“”。当映射页面加载时,它解析出“tg”,并将其传递给函数showStratChart(tg)和processGeoFm(tg)。但是在函数processGeoFm()中,它使用setZoom函数,地图视图跳到另一个位置。目前我已经为测试注释了processGeo

我正在尝试在单独的页面中创建指向地图的链接。当用户单击链接时,它将重定向到地图并显示与链接对应的地质多边形。然而,经过数小时的调试,我发现setZoom函数阻止了我这样做,我不知道为什么。如果单击“在地图上查看Tg”按钮,则会创建url“”。当映射页面加载时,它解析出“tg”,并将其传递给函数showStratChart(tg)和processGeoFm(tg)。但是在函数processGeoFm()中,它使用setZoom函数,地图视图跳到另一个位置。目前我已经为测试注释了processGeoFm()

 var lblTextPass = new String(window.location);
var equalIndex = lblTextPass.indexOf("=") + 1;
//window.alert(theleft);
if (equalIndex > 0) {
    //var delay = 2000;
    //setTimeout(function(){
        var fmLabel = lblTextPass.substring(equalIndex, lblTextPass.length);
//      //window.alert(fmLabel);
        //processGeoFm(fmLabel);
        showStratChart(fmLabel);
        map.setCenter(new google.maps.LatLng(36.027791, -91.188240));

        //if (map.getZoom()) {
            map.setZoom(9); 
        //}


     //},delay);

} else {
    processGeoFm("Ozarks");

}

如果我注释掉map.setZoom(9),地图将不会跳到另一个lat/lng。如果直接转到地图,地图将调用processGeoFm(“Ozarks”),它不会导致地图视图跳转,也不会在从地图上方的下拉菜单中选择某个对象(如Gra砾(tg))时调用processGeoFm()时发生跳转。我真的需要一些帮助。谢谢

另一个堆栈溢出问题让我找到了这个解决方案,我必须将它添加到我的processGeoFm函数中

 var zmListener = google.maps.event.addListenerOnce(map, "idle", function() {
            //this corrects bug with setZoom function when passing a variable from another page
            map.setZoom(7);

            map.setCenter(new google.maps.LatLng(34.75, -91.184)); //this ensures correct lat/lng
        }); 

    map.setCenter(new google.maps.LatLng(34.75, -91.184));
不知道为什么我要这么做