在javascript中访问google地图对象实例以在页面加载后更改地图选项?

在javascript中访问google地图对象实例以在页面加载后更改地图选项?,javascript,google-maps,google-maps-api-3,frontend,Javascript,Google Maps,Google Maps Api 3,Frontend,我有一个由后端服务动态生成的映射,该服务生成下面的javascript。在不修改下面的代码的情况下,是否有任何方法可以访问在下面的“initMap”函数中创建的google.maps.Map()的实例,以便在页面加载后更改“地图”选项 var googleMap_SearchResultsGoogleMapV31 = { addresses: [], initMap: function() { var bounds = new google.maps.LatLng

我有一个由后端服务动态生成的映射,该服务生成下面的javascript。在不修改下面的代码的情况下,是否有任何方法可以访问在下面的“initMap”函数中创建的google.maps.Map()的实例,以便在页面加载后更改“地图”选项

var googleMap_SearchResultsGoogleMapV31 = {
    addresses: [],
    initMap: function() {
        var bounds = new google.maps.LatLngBounds,
            mapOptions = {
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                center: new google.maps.LatLng(-37.8136, 144.9631)
            },
            map = new google.maps.Map(document.getElementById("page_layout_page_template_SearchResultsGoogleMapV31_map-canvas"), mapOptions);
        for (i = 0; i < googleMap_SearchResultsGoogleMapV31.addresses.length; i++) googleMap_SearchResultsGoogleMapV31.addAddressMarker(map, googleMap_SearchResultsGoogleMapV31.addresses[i], bounds, 300);
        setTimeout(function() {
            if (googleMap_SearchResultsGoogleMapV31.addresses.length > 1) {
                map.fitBounds(bounds);
                map.panToBounds(bounds)
            } else map.setZoom(4)
        }, 1500)
    },
    addAddressMarker: function(map, addressToLocate, markerBounds, infoMaxWidth) {
        var geocoder = new google.maps.Geocoder;
        geocoder.geocode({
            address: addressToLocate.address
        }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                googleMap_SearchResultsGoogleMapV31.addMarker(map, results[0].geometry.location, addressToLocate.title, markerBounds, addressToLocate.info, infoMaxWidth);
                googleMap_SearchResultsGoogleMapV31.addresses.length == 1 && map.setCenter(results[0].geometry.location)
            }
        })
    },
    addMarker: function(map, location, name, markerBounds, infoContent, infoMaxWidth) {
        markerBounds.extend(location);
        var marker = new google.maps.Marker({
            position: location,
            map: map,
            title: name,
            status: "active"
        });
        if (infoContent && infoContent != "") {
            var markerInfo = new google.maps.InfoWindow({
                content: "<div id='infoContent' class='mapInfoContent'>" + infoContent + "</div>",
                maxWidth: infoMaxWidth
            });
            google.maps.event.addDomListener(marker, "click", function() {
                markerInfo.open(map, marker)
            })
        }
    }
};
google.maps.event.addDomListener(window, "load", googleMap_SearchResultsGoogleMapV31.initMap)
var googleMap\u SearchResultsGoogleMapV31={
地址:[],
initMap:function(){
var bounds=new google.maps.LatLngBounds,
映射选项={
mapTypeId:google.maps.mapTypeId.ROADMAP,
中心:新google.maps.LatLng(-37.8136144.9631)
},
map=new google.maps.map(document.getElementById(“页面\布局\页面\模板\搜索结果GoogleMapv31 \地图画布”)、mapOptions);
对于(i=0;i1){
映射边界(bounds);
panToBounds地图(边界)
}else map.setZoom(4)
}, 1500)
},
addAddressMarker:函数(映射、addressToLocate、markerBounds、infoMaxWidth){
var geocoder=new google.maps.geocoder;
地理编码({
地址:addressToLocate.address
},功能(结果、状态){
if(status==google.maps.GeocoderStatus.OK){
googleMap\u SearchResultsGoogleMapV31.addMarker(地图,结果[0].geometry.location,addressToLocate.title,markerBounds,addressToLocate.info,infoMaxWidth);
googleMap\u SearchResultsGoogleMapV31.addresses.length==1&&map.setCenter(结果[0].geometry.location)
}
})
},
addMarker:函数(映射、位置、名称、标记边界、infoContent、infoMaxWidth){
扩展标记边界(位置);
var marker=new google.maps.marker({
位置:位置,,
地图:地图,
标题:姓名,
状态:“活动”
});
if(infoContent&&infoContent!=“”){
var markerInfo=new google.maps.InfoWindow({
内容:“+infoContent+”,
maxWidth:infoMaxWidth
});
google.maps.event.addDomListener(标记“单击”,函数(){
markerInfo.open(地图、标记)
})
}
}
};
google.maps.event.addDomListener(窗口“加载”,googleMap\u搜索结果GoogleMapv31.initMap)

如何声明
var谷歌地图
googleMap\u SearchResultsGoogleMapV31
之外,然后您可以在
initMap
函数中分配
googleMap=new google.maps.Map()
。为什么您不能更改代码?我不能更改代码,因为它是由第三方后端服务创建的(该服务不允许我设置默认缩放之外的地图选项)。