Bootstrap模式中的Google Map无法正常工作



我试图在Bootstrap Modal中显示一张Google Map,几天,我在这里搜索了所有答案,讨论了这个主题,但是到目前为止,对我没有任何帮助。我知道我必须在模态打开后使用调整大小触发器,确实我使用了它,但似乎对我无济于事,这非常令人沮丧。请帮助!

这是我使用的代码:

<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">&times;</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>  

我得到了以下内容,它可能会帮助其他人。

BootstrapDialog.show({
            title: 'Point on Map',
            message: ''<div id="selction_map"></div>'',
            onshown: function(dialogRef){
                initMap();
            }
        });

https://nakupanda.github.io/bootstrap3-dialog/

查看以下内容:JSFIDDLE可以为您服务

$("#myMapModal").ready(function() {
    $(window).resize(function() {
        google.maps.event.trigger(map, 'resize');
    });
    $('#myMapModal').modal('show');
    google.maps.event.trigger(map, 'resize');
    return map.setCenter(myLatlng);
});

最新更新