谷歌地图在隐藏的div div中心 [英] GoogleMap in hidden div off center

查看:144
本文介绍了谷歌地图在隐藏的div div中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google Map的GoMap jQuery插件。带地图的div默认为隐藏。我几乎想到如何正确显示地图,但不知怎的,我在揭示div后无法将地图居中。我尝试了所有我能找到的解决方案,现在我拥有下面的代码,但仍然无法正常工作。任何人都可以帮助我呢?

I use GoMap jQuery plugin for Google map. The div with the map is hidden by default. I almost figured how to display the map correctly, but somehow I'm unable to center the map after I reveal the div. I tried every solution I was able to find, right now I have the code below, which still doesn't work right. Anyone could help me with this? Thanks.

<h3><a class="showmap" href="#">Show map</a></h3>
<div id="map" style="height: 350px; width: 700px;"> </div>

<script type="text/javascript">
$(function() { 
$("#map").goMap({
markers: [{  
        latitude: 49.676196, 
        longitude: 13.444927, 
        html: { 
            content: 'Marker description', 
            popup: true 
        } 
    }], 
    hideByClick: false,
    zoom: 12
}); 
});

$(document).ready(function(){
    $("#map").hide();
});

$('.showmap').click(function(){
 $('#map').slideToggle('slow', function() {
  var center = $.goMap.map.getCenter();      
  google.maps.event.trigger($.goMap.map, 'resize');
  $.goMap.map.setCenter(center);
  });
});


推荐答案

您的解决方案几乎是完美的,但默认情况下,地图会平移以使infoWindow可见,什么会改变中心。

您可以禁用自动换盘:

Your solution is almost perfect, but by default the map will pan to make the infoWindow visible, what will change the center.
You may disable the AutoPan:

$("#map").goMap({
markers: [{  
        latitude: 49.676196, 
        longitude: 13.444927, 
        html: { 
            content: 'Marker description', 
            popup: true ,
            disableAutoPan:true//<--
        } 
    }], 
    hideByClick: false,
    zoom: 12
}); 
});

这篇关于谷歌地图在隐藏的div div中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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