title: Network link on Google Maps
body: <p>I have created a Google map in an HTML page with a KMZ overlay and it displays properly. I have then tried to use a network link to display the KML file in order to have it refresh periodically, since the data in the KML file content can change. This however does not work.</p>
  
  <p>The part of the HTML code for the Google Map and KML (that works) looks as follows (I have just entered a fake url).</p>
  
  <pre><code>&lt;script&gt;
      function initMap() {
      var windhoek = {lat: -22.8, lng: 17.6};
      var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 4.5,
          center: windhoek
      });
      var ctaLayer = new google.maps.KmlLayer({
        url: 'http://www.example.com/kml_file_ovelay.kmz',
        map: map
      });
  }
  &lt;/script&gt;
  &lt;script async defer
  src="https://maps.googleapis.com/maps/api/js?key=&amp;callback=initMap"&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>I have then created a network link file (network_link_file.kmz) that references this kml_file_ovelay.kmz file. </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;kml xmlns="http://earth.google.com/kml/2.1"&gt;
      &lt;NetworkLink&gt;
      &lt;Link&gt;
          &lt;href&gt;http://www.example.com.na/kml_file_ovelay.kmz&lt;/href&gt;
          &lt;refreshMode&gt;onInterval&lt;/refreshMode&gt;
          &lt;refreshInterval&gt;30&lt;/refreshInterval&gt;
      &lt;/Link&gt;
      &lt;/NetworkLink&gt;
  &lt;/kml&gt;
  </code></pre>
  
  <p>I have opened this file with Google Earth and it works as expected.</p>
  
  <p>The HTML file was changed to reference the network link file as follows.</p>
  
  <pre><code>&lt;script&gt;
      function initMap() {
      var windhoek = {lat: -22.8, lng: 17.6};
      var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 4.5,
      center: windhoek
      });
      var ctaLayer = new google.maps.KmlLayer({
        url: 'http://www.example.com/network_link_file.kmz',
        map: map
      });
      }
  &lt;/script&gt;
  &lt;script async defer
  src="https://maps.googleapis.com/maps/api/js?key=&amp;callback=initMap"&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>Now, the Google Map still appears, but the KMZ overlay never appears. I have tried different browsers to see if it may be a caching problem. It states in the Google Maps APIs documentation (<a href="https://developers.google.com/maps/documentation/javascript/kmllayer" rel="nofollow noreferrer">https://developers.google.com/maps/documentation/javascript/kmllayer</a>) that network links are supported for Google Maps to import data dynamically, so I must be doing something wrong, I assume in my network_link_file.kmz file.</p>
  
  <p>Does anyone know what may be causing this? My searches on this issue did not reveal anything useful as to what may be the problem in this case.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>---Answer provided by BarryHunter ---</p>
  
  <p>I have posted the same question on <a href="https://support.google.com" rel="nofollow noreferrer">https://support.google.com</a>. A post from BarryHunter provided the answer (thanks Barry!). Javascript can also be used to force the refresh as follows.</p>
  
  <pre><code>var ctaLayer = false;
  function refreshLayer() {
  if (ctaLayer)
      ctaLayer.setMap(null);
      ctaLayer = new google.maps.KmlLayer({
          url: 'http://www.example.com/kml_file_overlay.kmz?r=' + (new Date()).getTime(),
          map: map
      });
  }
  setInterval(refreshLayer, 10000);
  </code></pre>
  
  <p>With this approach, a Network Link file is not even required. Hope this helps others!</p>