Google 地图未出现在模态弹出窗口中

Google Map Does not appear in Modal Popup

我想在模式弹出窗口中显示 google 地图,但它似乎没有出现。需要帮助。

这里是 HTML -

<div id="map-canvas" style="width: 600px; height: 450px; background-color: grey;padding:0;margin:0"></div>

JS -

function initialize() {
    var myloc = new google.maps.LatLng(-34.397, 150.644);
    var mapOptions = {
        zoom: 17,
        center: myloc,
        scrollwheel: false
    };
    var map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
    var marker = new google.maps.Marker({
        position: map.getCenter(),
        map: map,
        animation: google.maps.Animation.BOUNCE
    });
    var contentString = '<div id="content" style="dir:rtl; text-align:right;">'+
            '<div id="siteNotice">'+
            '</div>'+
            '<h1 id="firstHeading" class="firstHeading"><h1>title here</h1>'+
            '<div id="bodyContent">'+
            '<p>description here</p>'+
            '</div>'+
            '</div>';
    var infowindow = new google.maps.InfoWindow({
        content: contentString,
        maxWidth: 250
    });
    google.maps.event.addListener(marker, 'click', function() {
        infowindow.open(map,marker);
    });
}
google.maps.event.addDomListener(window, 'load', initialize);

这是弹出预览图像 - Image Preview

您应该在显示的模式上使用 resize 来刷新您的地图:

$('modal-id').on('shown.bs.modal', function () 
{
    google.maps.event.trigger(map, "resize");
});

希望对您有所帮助。

我已经为模式弹出窗口中的静态地图加载添加了这个。

google.maps.event.addListener(map, "idle", function()
{
   google.maps.event.trigger(map, 'resize');
});