如何在Google地图中根据Windows大小控制缩放级别 [英] How to Control Zoom Level Based on Windows Size In Google Maps

查看:252
本文介绍了如何在Google地图中根据Windows大小控制缩放级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Bootstrap创建响应式Google地图。此处是我到现在为止所做的。我需要做的是设置一种方法来根据窗口大小控制地图的缩放级别。例如,当用户重新设置地图大小时,地图开始缩小并以另一种方式放大!你可以让我知道,如果这是可能的,我怎么能做到这一点?

I am trying to create a responsive Google Map using Bootstrap.Here is a sample of what I did till now . What I need to do is setting a method to control the map's zoom level based on the windows size.For example as when as user re-size the map the map start zooming out and zooming in on the other way! Can you please let me know if this is possible and how I can do it?

var map;
var panorama;
jQuery(function($) {
$(document).ready(function() {
    var latlng = new google.maps.LatLng(49.241943,-122.889318);
    var myOptions = {
        zoom: 18,
        center: latlng,
        panControl: true,
        zoomControl: true,
        zoomControlOptions: {
                              style: google.maps.ZoomControlStyle.SMALL
                            },
        mapTypeControl: false,
        scaleControl: false,
        streetViewControl: false,
        overviewMapControl: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
       };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    });
 });


推荐答案

您可以使用此更改地图的缩放级别:

You can change the zoom level of the map with this:

var mq = window.matchMedia( "(min-width: 768px)" );
if (mq.matches) {
    map.setZoom(6);
}

这篇关于如何在Google地图中根据Windows大小控制缩放级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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