我试图让谷歌地图出现在香草引导选项卡中。我直接从 Bootstrap 文档中构建了一个小提琴,其 Gmap 脚本与 Google 推荐的非常相似。
我将map
对象转储到 console.dir 并且它已正确初始化。在早期的项目中,我可以使用该resize
功能在选项卡中显示地图——但它似乎不适用于 Bootstrap。
有没有人得到这个工作?
这是通用的 jsfiddle—— http://jsfiddle.net/B4zLe/4/
编辑:添加代码
JAVASCRIPT:
var map;
jQuery(function($) {
$(document).ready(function() {
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
console.dir(map);
google.maps.event.trigger(map, 'resize');
$('a[href="#profile"]').on('shown', function(e) {
google.maps.event.trigger(map, 'resize');
});
});
});
HTML:
<div>
<div class="bs-docs-example">
<ul id="myTab" class="nav nav-tabs">
<li class="active"><a href="#home" data-toggle="tab">Home</a></li>
<li><a href="#profile" data-toggle="tab">Map</a></li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="home">
<p>Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
</div>
<div class="tab-pane fade" id="profile">
<div id="map_canvas"></div>
</div>
</div>