I created a hello world program to load a local kml file (borrowed from google's docs):
var ctaLayer = new google.maps.KmlLayer("http://localhost:8080/kml/cta.kml");
This does not work (nothing gets loaded).
However, when I change that line to:
var ctaLayer = new google.maps.KmlLayer("http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml");
it loads properly. Both kml files are identical. What do I need to do to get it to load when serving it myself? (I tried both absolute and relative paths, and I know the paths I am using are correct...)
Also I added the correct mime type to my appserver's config file:
<mime-mapping>
<extension>kml</extension>
<mime-type>application/vnd.google-earth.kml+xml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>kmz</extension>
<mime-type>application/vnd.google-earth.kmz</mime-type>
</mime-mapping>
But it still doesn't load.
I found this in google's docs:
The Google Maps API supports the KML and GeoRSS data formats for displaying geographic information. These data formats are displayed on a map using a KmlLayer object, whose constructor takes the URL of a publicly accessible KML or GeoRSS file.
So I guess what I am trying to do is not possible without serving the kml from a publicly accessible url...unless someone can prove otherwise
You can import more than one kml file into Earth for the web. Just repeat the import procedure and the files will be listed in the "KML files" section of the project panel.
KML is a file format used to display geographic data in an Earth browser such as Google Earth. KML uses a tag-based structure with nested elements and attributes and is based on the XML standard. All tags are case-sensitive and must appear exactly as they are listed in the KML Reference.
The KML can't be accessed since it's on your local machine and google can't access that since it doesn't know how to get to localhost:8080
Unfortunately you cannot use "localhost". You have two choices:
Choice #1 might not be an option for those working on defense contracts and deal with sensitive information as the kml is sent to google in the background and rendered on the map.
This website, display-kml.appspot.com, requires that you copy/paste the entire KML file into the website. Alternatively, you can use Dropbox to host the KML file using your public folder. Within the public Dropbox folder, there is a right-click context menu that allows you to copy the URL.
Update:The appspot website has a history of being unstable. As of January 2019, the website appears to be working.
REFERENCES:If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With