jQuery标签中重新加载谷歌地图

jQuery标签中重新加载谷歌地图

本文介绍了如何在Bootstrap jQuery标签中重新加载谷歌地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用gmaps.js在Bootstrap标签中加载2张地图。会发生什么,是第一个地图加载正常,但是当第二个标签(隐藏)被点击时,地图不能正确加载。经过广泛的谷歌搜索之后,我意识到这与Google地图在点击标签时需要调整大小有关,因为谷歌地图不能很好地隐藏标签。然而,在尝试了很多事情后,我无法实现它的工作。这是我的小提琴:

I'm using gmaps.js to load 2 maps in Bootstrap tabs. What happens, is the first map loads fine, but when the second tab (hidden) is clicked, the map doesn't load properly. After extensive Googling, I realize that this has to do with the Google map needing to be resized upon the click of the tab, as Google maps don't play nicely with hidden tabs. However, after trying many things, I just can't get it to work. Here's my fiddle: http://jsfiddle.net/7PueE/

(显示晚于点击时触发,当该选项卡已经可见时): 

trigger the resize-event of the window when a tab is shown(shown fires later than click, when the tab is already visible):

$('.nav-tabs').on('shown.bs.tab', function () {
    google.maps.event.trigger(window, 'resize', {});
});

这篇关于如何在Bootstrap jQuery标签中重新加载谷歌地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 06:40