title: How can I make my google map load within a jquery tab?
body: <p>My google maps will not load within the first tab (active tab) of my dcodes tabs jquery script.  I believe the map is being initialized before the active tab div is visible.  Some guys, as a work around, initialized() later on in the script or when the tab is actually clicked and opened.  This will not work for me as I have multiple maps being loaded on the same page and a php loop is passing variables to javascript as each function is called.</p>
  
  <p>If I have to do without the tabs, I will.  But, it will make my page look a lot cleaner if I could put my maps into a tab.</p>
  
  <p>When I comment out the lines that have hide(), the maps do appear within the tab.</p>
  
  <p>I am using Google Maps API v3</p>
  
  <p>Opera Tabs (Style 4) <a href="http://www.dcodes.net/2/docs/tabs.html" rel="nofollow noreferrer">http://www.dcodes.net/2/docs/tabs.html</a></p>
  
  <p>Here is the link to the <a href="http://jsfiddle.net/67wu9/1/" rel="nofollow noreferrer">js fiddle code</a> which I pulled out of view page source.</p>
  
  <p>I did try storing the display_kmlmap() function into a php variable and then printing it after the javascript for the tabs to see if that made a difference and it didn't.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>   &lt;script type="text/javascript"&gt; 
  function display_kmlmap(kmlmapid, kmlurllink)
  {
      var kmlmap = kmlmapid;
      var kmlUrl = 'http://www.example.com/test/'+ kmlurllink;
      //document.write(kmlmap);
      //document.write(kmlUrl);
      var map_options = { };  
      var map = new google.maps.Map(document.getElementById(kmlmap),map_options);
  
     // var kmlUrl = 'http://www.example.com/test/PW-Files/19/kml/161091.kml';
     var kmlOptions = { mapTypeId: google.maps.MapTypeId.SATELLITE,map: map
      };
  
      var kmlLayer = new google.maps.KmlLayer(kmlUrl, kmlOptions);
  }
  &lt;/script&gt;
  
   &lt;!-- Note:  I have these files on my local drive, but have listed the hosted files on here so you can access them. --&gt;
      &lt;!-- DC Tabs CSS --&gt;
  &lt;link type="text/css" rel="stylesheet" href="http://cdn.dcodes.net/2/tabs/css/dc_tabs.css" /&gt;
  &lt;!-- jQuery Library (skip this step if already called on page ) --&gt;
  &lt;script type="text/javascript" src="http://cdn.dcodes.net/2/jquery.min.js"&gt;&lt;/script&gt; &lt;!-- (do not call twice) --&gt;
  &lt;!-- DC Tabs JS --&gt;
  &lt;script type="text/javascript" src="http://cdn.dcodes.net/2/tabs/js/dc_tabs.js"&gt;&lt;/script&gt;
  
      &lt;!-- DC Opera Tabs Start --&gt;
  &lt;div class="dc_tabs_type_4_container" style="width:90%; height:auto;"&gt;
    &lt;ul id="dc_tabs_type_4"&gt;
      &lt;!-- Tab Captions --&gt;
      &lt;li&gt;&lt;a href="#" title="red-tab1"&gt;Aerial View&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#" title="red-tab2"&gt;Listing Details&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#" title="red-tab3"&gt;Videos&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#" title="red-tab4"&gt;Printable Docs&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
    &lt;div id="dc_tabs_type_4_content" style="height:auto;"&gt; &lt;!-- Tab Content Container --&gt;
  
      &lt;!-- Tab 1 Start --&gt;
      &lt;div id="red-tab1"&gt;
  
      &lt;?php
  $dirname = "PW-Files/$listingid/kml/";
  $kmls = glob($dirname."*");
   $html = "";
  //Display kmls using foreach loop
  foreach($kmls as $kml){
  
   // display_kmlmap()
   $info = pathinfo($kml);
  $file_name =  basename($kml,'.'.$info['extension']);
  //print $kml;
  $html .= "&lt;div id=\"$file_name\" style=\"width:500px; height:300px; float:left\"&gt;&lt;/div&gt;";
  ?&gt;
  &lt;script type="text/javascript"&gt;
   $(document).ready(function() {
              if ($('#&lt;?php echo"$file_name";?&gt;').length != 0) {
  
  display_kmlmap(&lt;?php echo json_encode($file_name);?&gt;, &lt;?php echo json_encode($kml);?&gt;);
  
   }
        });
  
  &lt;/script&gt;
  &lt;?php
  }
      echo "$html";
  
  ?&gt;
  
     &lt;p&gt;Where is the map?&lt;/p&gt;
  
      &lt;/div&gt;
      &lt;!-- Tab 1 End --&gt;
  
      &lt;!-- Tab 2 Start --&gt;
      &lt;div id="red-tab2"&gt;
        &lt;h2&gt;Tab Two&lt;/h2&gt;
        &lt;p&gt;Aenean dui nulla, egestas sit amet auctor vitae, facilisis id odio. Donec dictum gravida feugiat.&lt;/p&gt;
        &lt;p&gt;Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Cras pretium elit et erat condimentum et volutpat lorem vehicula&lt;/p&gt;
        &lt;p&gt;Morbi tincidunt pharetra orci commodo molestie. Praesent ut leo nec dolor tempor eleifend.&lt;/p&gt;
      &lt;/div&gt;
      &lt;!-- Tab 2 End --&gt;
  
      &lt;!-- Tab 3 Start --&gt;
      &lt;div id="red-tab3"&gt;
        &lt;h2&gt;Tab Three&lt;/h2&gt;
        &lt;p&gt;Non erat laoreet ullamcorper. Pellentesque magna metus, feugiat eu elementum sit amet, cursus sed diam. Curabitur posuere porttitor lorem, eu malesuada tortor faucibus sed.&lt;/p&gt;
        &lt;h3&gt;Duis pulvinar nibh vel urna&lt;/h3&gt;
        &lt;p&gt;Donec purus leo, porttitor eu molestie quis, porttitor sit amet ipsum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec accumsan ornare elit id imperdiet. &lt;/p&gt;
        &lt;p&gt;Suspendisse ac libero mauris. Cras lacinia porttitor urna, vitae molestie libero posuere et. &lt;/p&gt;
      &lt;/div&gt;
      &lt;!-- Tab 3 End --&gt;
  
      &lt;!-- Tab 4 Start --&gt;
      &lt;div id="red-tab4"&gt;
        &lt;h2&gt;Tab Four&lt;/h2&gt;
        &lt;p&gt;Magnis dis parturient montes, nascetur ridiculus mus. Nullam ac massa quis nisi porta mollis venenatis sit amet urna. Ut in mauris velit, sed bibendum turpis.&lt;/p&gt;
        &lt;p&gt;Nam ornare vulputate risus, id volutpat elit porttitor non. In consequat nisi vel lectus dapibus sodales. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent bibendum sagittis libero.&lt;/p&gt;
      &lt;/div&gt;
      &lt;!-- Tab 4 End --&gt;
  
    &lt;/div&gt; &lt;!-- /dc_tabs_type_4_content --&gt;
  &lt;!-- DC Opera Tabs End --&gt;
  &lt;div class="dc_clear"&gt;&lt;/div&gt; &lt;!-- line break/clear line --&gt;
  &lt;!-- DC Opera Tabs Settings --&gt;
  &lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
  /* Tabs 4 */
  
  $(document).ready(function() {
      $("#dc_tabs_type_4_content div").hide(); // Initially hide all dc_tabs_type_4_content 
      $("#dc_tabs_type_4 li:first").attr("id","current"); // Activate first tab
      $("#dc_tabs_type_4_content div:first").fadeIn(); // Show first tab dc_tabs_type_4_content
  
      $('#dc_tabs_type_4 a').click(function(e) {
          e.preventDefault();        
        $("#dc_tabs_type_4_content div").hide(); //Hide all dc_tabs_type_4_content 
          $("#dc_tabs_type_4 li").attr("id",""); //Reset id's
          $(this).parent().attr("id","current"); // Activate this
          $('#' + $(this).attr('title')).fadeIn(); // Show dc_tabs_type_4_content for current tab
      });
  })();
  
  &lt;/script&gt;
  </code></pre>
  
  <p>This is the closest thing i've found on the web: <a href="https://stackoverflow.com/questions/3014156/google-maps-and-jquery-tabs">Google Maps and jQuery Tabs</a> by Dom.  He changed hide() to css.visibility.  However, his code is a little different from mine so i'm not sure what I should do to mine since I am not advanced enough with javascript and css, but I would like to learn.</p>
  
  <p>Here is Dom's code which he claimed worked for him:</p>
  
  <pre><code> $(document).ready(function() {
  
          //Default Action
          $(".tab_content").css({'visibility':'hidden'  , 'position':'absolute'});
          $("ul.tabs li:first").addClass("active").show(); 
          $(".tab_content:first").css({'visibility':'visible' , 'position':'static'}); 
  
          //On Click Event
          $("ul.tabs li").click(function() {
              $("ul.tabs li").removeClass("active");
              $(this).addClass("active"); 
              $(".tab_content").css({'visibility':'hidden' , 'position':'absolute'}); 
              var activeTab = $(this).find("a").attr("href"); 
              $(activeTab).css({'visibility':'visible'  , 'position':'static'});
              return false;
          });
  
      });
  </code></pre>