Google Maps Not Working in jQuery Tabs

前端 未结 13 1848
滥情空心
滥情空心 2020-12-09 22:56

Google maps not working when placed inside jQuery tabs is a question that\'s all over the web. In my research so far none of the solutions seem to work. Hopefully someone he

13条回答
  •  天命终不由人
    2020-12-09 23:17

    No of the above answers are completely correct. The problem occurs because the map canvas is set to width:0; height:0 by default before loading and then expects you to either pass the dimension or get the dimensions from the parent, as this is inside jQuery tabs there are no dimensions.

    As mentioned above bind to the click event of your tab and set the map_canvas dimension then call the google.maps.event.trigger()

     $(function(){
    
    $('#maptab').bind('click',function() {
                var w = $('#map_view').width();
                var h = $('#map_view').height();
                $('#map_canvas').css({ width: w, height: h });
               google.maps.event.trigger(map, 'resize');
    
            });
    
    });
    

提交回复
热议问题