0

I can't make this work. I have a JavaScript program that should upload a KML and it does not work. Uploading the same KML manually in Google Maps works perfectly

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>GeoRSS Layers</title>
    <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 100%;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>
      function initMap() {
        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 12,
          center: {lat: 40.45, lng: -3.8}
        });
/* otra opcion era 'http://maps.google.com/maps?q=https://github.com/churruscat/files/blob/master/KMLtrak.KML'*/
        var georssLayer = new google.maps.KmlLayer({
          url: 'https://drive.google.com/open?id=15OVgNwtVbLVARkHJD3F8P_bEfG9oJ4Lu',
        });
        georssLayer.setMap(map);
      }
    </script>
    <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAcjfUbZQhM3Zcmncn18-v3LOqYMTFhe-Q&callback=initMap">
    </script>
  </body>
</html>
0

The Google Drive link that you're using (https://drive.google.com/open?id=15OVgNwtVbLVARkHJD3F8P_bEfG9oJ4Lu) doesn't actually open/download the KML file itself, but rather opens a web page which displays the file. This won't work with the Google Maps API, since that requires a direct link to the KML or KMLZ file itself.

There are ways to get a direct download link for a file hosted in Google Drive (so long as the file is publicly viewable). I'm not sure if it's officially supported, but if you search the web for "google drive direct download link", you should find instructions. for creating a download link with the ID of your file. I think your file should work with this URL:

https://drive.google.com/uc?export=download&id=15OVgNwtVbLVARkHJD3F8P_bEfG9oJ4Lu

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.