简体   繁体   中英

Why is KML not loading in Google Maps?

I have a KML file that I am trying to load into Google maps. It zooms somewhere in the water with no route trace. This is the code I am trying:

    var kmlLayer = new google.maps.KmlLayer(kml);
    kmlLayer.setMap(this.googlemap);

"this.googlemap" has a Google map object. It is very simple example, but maybe I am missing something or my KML is not in the right format. My KML file can be download here: http://temp-share.com/show/gFHKdyG0Y . Can anyone help?

Google Map needs to be able to access this KML file direclty, in other words, your KML file must be publicly available, and must end with .kml or .kmz extensions (I believe).

To make sure the KML file itself is correct, you can always go to maps.google.com and put the URL in the search bar, it should be automatically recognized and rendered.

As Bill says, the KML file needs to be publicly downloadable, however The URL you linked to in the question abov does not link directly to the file itself, it links to an HTML page that you can visit to download the file. You may have to try a different service, as it doesn't appear that you can download directly from that location without going through the intermediate page.

You will know you are using the right link when you paste the link into the browser, and it immediately prompts you to download the file.

If you still have problems, make sure to post more of your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM