title: Google Maps KML Loading - 414 Request URI too large
body: <p>I am currently building a Google Maps project that will dynamically load and unload various KMZ files based on user input. It works fine for roughly 8 layer loads/unloads, but then Google Maps breaks down with the 414 error. I've traced the problem down to the stored string the API is generating to refer to each KML layer. </p>
  
  <p>Here's the code that runs when a layer is clicked:</p>
  
  <pre><code>function showLayer(layername) {
    if (layers[layername].kml === undefined) {
      layers[layername].kml = loadKML(layers[layername].file, layers[layername].options);
    }
    layers[layername].kml.setMap(map);
    redrawRoutes(layers[layername].kml);
  }
  </code></pre>
  
  <p>And the loadKML function:</p>
  
  <pre><code>function loadKML(file, options) {
    var path = kmlDir + file;
    options = options || { preserveViewport: true };
    layer = new google.maps.KmlLayer(path, options);
    return layer;
  }
  </code></pre>
  
  <p>Basically my goal is to only load each KML file once, store it in an object, and just reference that on subsequent loads/unloads. The problem here is that inside the Javascript Object that <code>new google.maps.KmlLayer</code> generates, a big long string</p>
  
  <pre><code>"kml:cj5TNh3iqySpI_DAGiDgbSJESQ-dakZTiMY09US6imjvFNPMTIIYNAg|ks:;dc:cg;ts:44610546|kv:3|api:3"
  </code></pre>
  
  <p>and appends this to the request URI each time. This adds up rather quickly, and after 7-8 appends the URI is too long and any subsequent requests are ignored.</p>
  
  <p>Is there a way around using this long request string, can I force it to use a custom string, or just clear the URI each time? I will only be dealing with ~6 total files, and I'd really like to be able to handle as many layer loads/unloads as possible.</p>