0

I created kml file from ArcMap and imported into my Google maps, it works. Not sure if you can open this URL: https://www.google.com/maps/d/edit?mid=13TuHmGuW9nnE-8TACTfGLdDDf6o&ll=38.90133009121122%2C-77.01476049999996&z=12

Now I want to display my map using Java API and I used this code https://developers.google.com/maps/documentation/javascript/kml tweaked it a little bit, inserted my API_Key at the end of the script but the problem is

<script>
      var map;
      var src = 'https://myGoogleMapURL

should be with the .kml extension if I am not mistaken. My question is, how do I generate kml file/url from my map URL mentioned above. I tried adding &output=kml at the end of the Google map URL as some people suggested but it does not work.

  • Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. – Midavalo Mar 27 '17 at 20:23
1

If I am not mistaken this line is supposed to be a link to where you KML file is hosted. The link that you posted at the beginning will not work with the google maps api. You need to be able to point to the raw file in which you are hosting.

You will need to find a place on the cloud for you to store your kml file or simply point to the directory on your computer.

Here is a link with some instructions on how to go about doing this using your google drive

  • As stated in the begging of my initial post, KML file is already hosted/imported into Google Maps (under my account), simply create new Map and there is an option to import KML file. It is there (first link provided) but for API to work I need that URL with KML extension. AvidDabbler, I`ll check the instructions that you provided as well. Tanks – Klika Mar 27 '17 at 18:43
  • In order to use a KML file in Google Maps API the file has to be hosted somewhere else other than My Maps. The example url that they show on the API (developers.google.com/maps/documentation/javascript/examples/…) is pointing to a raw KML file and not a My Maps link. If you were to actually go to that URL it would take you to a download of a KML file not a Google My Map – AvidDabbler Mar 27 '17 at 19:44
  • That`s weird, for my assignment my instructor gave us a couple of options where to store our KML file, one is Google maps and the other is ArcMap online (this one requires different approach). Someone is wrong here ........ – Klika Mar 27 '17 at 19:56
1

I found out that you don't need to download and upload it. If you are using MyMaps and download as the KML there is already a link present within the file - open it up in a text editor (or simply click and drag the download into your browser and there should be a line . You can copy the link inside the square brakets and there you are.

I hope this helps.

1

You can download the data directly from MyMaps with this syntax

https://www.google.com/maps/d/u/0/kml?mid={MAP_ID}&forcekml=1

The MAP_ID is the ID in the URL when you've got the MyMap open,

eg. your map

https://www.google.com/maps/d/edit?mid=13TuHmGuW9nnE-8TACTfGLdDDf6o&ll=38.90133009121122%2C-77.01476049999996&z=12

will be...

https://www.google.com/maps/d/u/0/kml?mid=13TuHmGuW9nnE-8TACTfGLdDDf6o&forcekml=1

or adding to your Google Maps Javascript API. But there is a limit of 2mb data size for this.

    let my_url = 'https://www.google.com/maps/d/u/0/kml?mid={MAP_ID}&forcekml=1'

    let kmlLayer = new google.maps.KmlLayer(my_url, {
      suppressInfoWindows: true,
      preserveViewport: false,
      map: map
    });

    kmlLayer.addListener('click', function(event) {
      var content = event.featureData.infoWindowHtml;
      var testimonial = document.getElementById('capture');
      testimonial.innerHTML = content;
    });

Take note of your sharing settings. This does expose your data publicly (If they have the link or even the ID) but that's whats needed to download the data directly

Access Control for MyMaps

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.