如何以编程方式更改Google地图的缩放级别?

问题描述:

function displayMapAndClick ()
    {
        var latlng    = new google.maps.LatLng (29.0167, 77.3833);
        var myOptions = 
        {
            zoom:zm,
            center:latlng,
            mapTypeId:google.maps.MapTypeId.ROADMAP
        };

        map = new google.maps.Map (document.getElementById ("map"), myOptions);
        directionsDisplay.setMap (map); 
    }

zm是设置为默认7的全局变量.

Where zm is a global variable set to default 7.

现在,我希望通过该程序更改此地图的缩放级别.

Now, I wish to change the zoom level of this map thorough this program.

在不重新初始化地图或强制重新初始化地图的情况下该怎么做?

What is the way to do that without re-initializing the map, or is re-initializing the map compulsory?

使用setZoom()方法> google.maps.Map 类.

Use the setZoom() method from the google.maps.Map class.

var mapOptions = {
  /* Initial zoom level */
  zoom: 8
  ...
};
map = new google.maps.Map(..., mapOptions);
/* Change zoom level to 12  */
map.setZoom(12);