-1

I want to make google map on wizard form, but the map cannot load properly and only show a half. I tried with resizing but the map still can't show fully. Thanks

<div class="row">
    <div class="col-sm-6">
        <div id="gmaps" style="width: 100%; height: 417px;"></div>
    </div>
</div>

I used bootstrap responsive.

    $(function ()
{
    $("#wizard").steps({
        headerTag: "h2",
        bodyTag: "section",
        transitionEffect: "slideLeft"
    });
});


var map;
function initialize() {
   var mapOptions = {
   zoom: 8,
   center: new google.maps.LatLng(-34.397, 150.644)
};
map = new google.maps.Map(document.getElementById('gmaps'),
  mapOptions);
}

google.maps.event.addDomListener(window, 'load', initialize);
google.maps.event.addDomListener(window, "resize", resizingMap());
$('#wizard').on('changed.fu.wizard', function(){
    resizeMap();
});
function resizeMap(){
    if(typeof map == "undefined") return;
    setTimeout(function(){resizingMap();} , 400);
}
function resizingMap(){
    if(typeof map == "undefined") return;
    var center = map.getCenter();
    google.maps.event.trigger(map,"resize");
    map.setCenter(center);
}

1 Answers1

0

I think, map use the pixel value of the container and % does not work in some cases/browsers.

I did something in the past like this:

when the map is loaded completely, update the size of your container, using the parent size maybe.

google.maps.event.addListenerOnce(map, 'idle', function(){
    // do something only the first time the map is loaded
});

Read this for more information: How can I check whether Google Maps is fully loaded?

Community
  • 1
  • 1
Soley
  • 1,716
  • 1
  • 19
  • 33