如何以编程方式更改Google地图的缩放级别? [英] How to change the zoom level of Google maps programmatically?

查看:91
本文介绍了如何以编程方式更改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);

这篇关于如何以编程方式更改Google地图的缩放级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆