几天来,我试图在引导模式中显示谷歌地图,我在这里搜索了所有讨论这个主题的答案,但直到现在对我没有任何帮助。我知道在模式打开后我必须使用调整大小触发器,并且确实我使用了它,但似乎对我没有任何作用,这非常令人沮丧。请帮忙!
这是我使用的代码:
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
myLatlng = new google.maps.LatLng(32.0260053,34.8987034);
function initialize() {
var myOptions = {
zoom: 14,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'),
myOptions);
$('.myMapModal').on('show.bs.modal', function() {
google.maps.event.trigger(map, 'resize');
return map.setCenter(myLatlng);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
的HTML:
<div class="modal myMapModal fade" id="myMapModal" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">#f16#</h4>
</div>
<div class="modal-body map-modal">
<div class="container">
<div class="row">
<div id="map-canvas" style="width: 500px; height: 480px;"></div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">סגירה</button>
</div>
</div>
</div>
</div>