Search code examples
google-mapsgoogle-maps-api-3gmaps4rails

Gmaps4rails: adjustMapToBounds after changing the map size


I would like to readjust the map after resizing the map container. I did the following, but it does not work. What am I missing?

Gmaps.map.callback = function() {
    var g4map = Gmaps.map,
    map = g4map.map;

    google.maps.event.addListenerOnce(map, 'idle', function(){
        $("#map").animate({height: 300});
        g4map.adjustMapToBounds();
    });
};

Thanks


Solution

  • Ok, I found the answer to my question... I had to trigger the resize event on the map to update the bounds.

    Gmaps.map.callback = function() {
        var g4map = Gmaps.map,
        map = g4map.map;
    
        google.maps.event.addListenerOnce(map, 'idle', function(){
            $("#map").animate({height: 300}, function() {
                google.maps.event.trigger(map, "resize");
                g4map.adjustMapToBounds();
            });
        });
    };