title: Google Maps refresh traffic layer
body: <p>In my Rails app, the background consists of a fullscreen div with Google Maps and a traffic layer. 
  This is what gets called on page load:</p>
  
  <pre><code>$(function () {  
    updateMap();
  });
  </code></pre>
  
  <p>The updateMap function creates a Google Map on the div element 'google_map':</p>
  
  <pre><code>function updateMap()  {
        var latlng = new google.maps.LatLng(52.157927, 4.704895);
      var myOptions = {
        zoom: 10,
        center: latlng,
        disableDefaultUI: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      var map = new google.maps.Map(document.getElementById("google_map"),
          myOptions);
      var trafficLayer = new google.maps.TrafficLayer();    
      trafficLayer.setMap(map);
      updateTrafficOnMap(map, trafficLayer);    
  }
  </code></pre>
  
  <p>The last call is to this function: </p>
  
  <pre><code>function updateTrafficOnMap(map, overlay)
  {
      overlay.setMap();
      overlay = null;
      var trafficLayer = new google.maps.TrafficLayer();    
      trafficLayer.setMap(map);
  
      setTimeout(function(){ updateTrafficOnMap(map, trafficLayer) }, 60000);
  }
  </code></pre>
  
  <p>Which is supposed to update the traffic layer every minute.</p>
  
  <p>Now the div is loaded correctly on page load, the layer is loaded too. However, this never updates, so there's no real time traffic information unless you reload the whole page.</p>
  
  <p>Anyone knows the magic word to make the traffic layer refresh properly?</p>