sajalsuraj
sajalsuraj

Reputation: 992

Google Map Does not appear in Modal Popup

I want to show google maps in modal popup, but it doesn't seem to be appeared. Need Help.

Here is the 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);

Here is the Popup preview image - Image Preview

Upvotes: 4

Views: 9018

Answers (2)

user9561986
user9561986

Reputation:

I have added this for a static map load which is in the modal popup.

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

Upvotes: 3

Zakaria Acharki
Zakaria Acharki

Reputation: 67505

You should use resize on modal shown to refresh your map:

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

Hope this helps.

Upvotes: 8

Related Questions