谷歌地图缩放不会设置功能

时间:2015-06-01 14:48:14

标签: javascript jquery google-maps

所以我在这里处理我的地图,由于某些原因,当我调用特定功能时,我似乎无法设置缩放。以下是我完成此任务的内容:

function mapReturn(map){
    $('#job-info').on('click', '#map-return', function(e){
        e.preventDefault(e);
        $('#job-info').css('display' , 'none');
        $('#map-canvas').cass('display', 'block');
        redrawMaps(map);  //redraw maps is very the zoom is suppose to change
        map.fitBounds(bounds);  //global variable bounds not needed here
    });
}

function redrawMaps(map){
    map.setCenter(new google.maps.LatLng(39.0111, -95.6752);
    map.setZoom(7); //i want the zoom to set here but it won't
    google.maps.event.trigger(map, 'resize');
}

我最终会建立一个逻辑结构,根据你当前所处的位置设置缩放级别,但是现在我希望它至少可以缩放到一个级别。所以回顾一下,我有一个返回上一个视图的按钮,当我点击它时,无论如何都会一直缩放,我只想让它放大到上一个缩放级别。再次感谢大家!

编辑:要清楚,已经设置了定义和初始化地图的代码,这是正在使用的代码片段,以及代码集中唯一无法正常运行的部分。为了完成起见:

//here are the map options that I used
var mapOptions = {
    center : new google.maps.LatLng(39.0111, -95.6752),
    zoom : 4,
    zoomControl : false,
    panControl : false,
    mapTypeControl : false,
    streetViewControl : false,
    draggable : false,
    scrollWheel : false
};

//here is where I initialize the map object 
var map = new google.maps.Map(document.getElementById('map-canvas', mapOptions);

1 个答案:

答案 0 :(得分:1)

在触发map.setZoom事件后调用resize(可能还需要在调整大小后设置中心):

function redrawMaps(map){
    google.maps.event.trigger(map, 'resize');
    map.setCenter(new google.maps.LatLng(39.0111, -95.6752);
    map.setZoom(7);
}