Ihavethefollowingproblem,whenloadingGoogleMapsv3inaModalwiththeBootstrapFrameworkthemapisnotdisplayedproperly.
Followthecode:
<!DOCTYPEhtml><html><head><metacharset="UTF-8">
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" />
<style>
html, body, #map-canvas {
height: 400px;
margin: 0px;
padding: 0px
}
</style>
</head>
<body>
<a href="#" class="btn btn-default" id="openBtn">Open modal</a>
<div class="modal fade" tabindex="-1" role="dialog" id="mapmodals">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Peggy Guggenheim Collection - Venice</h4>
</div>
<div class="modal-body">
<div id="map-canvas"></div>
</div>
<div class="modal-footer">
<button type="button" class="close" data-dismiss="modal">Fechar</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script><scriptsrc="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
<script>
$(function () {
$("#mapmodals").on('shown.bs.modal', function () {
google.maps.event.trigger(map, 'resize');
});
$("#openBtn").click(function () {
$('#mapmodals').modal('show');
});
});
var map;
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(-34.397, 150.644)
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</body>
</html>
JSFiddle with example error.