简体   繁体   中英

Load XML data into a KML file with JavaScript

I'm trying to load information from a .xml file (located in a .kmz archive) into the description of a placemark using javascript. The goal is to display the information from the .xml file in an html table in the description. I've gotten everything working, with the exception that I can't seem to access the .xml file from the .kml file. I'm trying to use an XMLHttpRequest() to load the file from the .kmz. It works just fine as an html file, but when i put the html/javascript into a description tag of the .kml, nothing loads at all.

Does anyone know if this is even possible to do? If so, how? If not, any other suggestions?

Thanks in advance for the help!

Is this using the Google Earth API? If so, note that script tags, amongst others, are stripped out by default. You can work around this if needed as described at https://developers.google.com/earth/documentation/balloons#getballoonhtmlunsafe

If this is KML being loaded into the Google Earth client, javascript is allowed (with the exception of things like alerts which bring up a browser dialog).

However it's quite possible, for example if you are loading a separate KMZ in your XHR request, amongst a variety of other reasons, that you're getting a cross domain error (basically because you'll be loading a local file with file:// versus http://). To test this, I would recommend hosting the XML on a server somewhere, and trying to see if that works.

If so, but it does not work locally, please paste a link to your KMZ, or at least paste your main KML within the KMZ, and the associated file structure within the KMZ.

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