I'm trying to put a Google Map inside a Bootstrap content-tab (this). This is my code for the map:
<style>
#map_canvas {
width: 500px;
height: 400px;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var mapOptions = {
center: new google.maps.LatLng(44.5403, -78.5463),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, mapOptions);
};
google.maps.event.addDomListener(window, 'load', initialize);
</script>
this is where I place the map_canvas div:
<div class="tab-content">
...other divs here...
<div class='tab-pane fade' id='contact'>
<div class="row">
<div id="send_email" class='span4 pull-right'>
...blablabla a form here...
</div>
<div id="information" class='span8'>
<ul>...contact info...</ul>
<div id="map_canvas"></div>
</div>
</div>
</div>
This is the code for the divs:
$('#navtabs a').click(function (e) {
e.preventDefault();
$(this).tab('show');
});
Really, nothing special about it. Yet for some reason the map is off to the side, and looks like this:
If I try and move it it just auto-fixes itself to be half-outside like in the picture. ommiting bootstrap.css solves the problem. Putting #map_canvas
outside the content-tabs also solves the problem. Yet I can't tell exactly what's screwing it up.
It isn't related to the max-width issue as suggested here, since I'm using bootstrap is 2.3.2 which addresses it and includes these lines by default (adding them to my own css doesn't help either):
#map_canvas img,
.google-maps img {
max-width: none !important;
}
I tried playing with chrome developer tools and scanning the divs and its parents, I went over the .tab-content
inside bootstrap css, I tried ommiting the entirety of the img attributes inside the bootstrap.css, I tried many other solutions from SO, to no avail.
Any help would be much appreciated.