How can I upload a KML file to a website for an organization with multiple locations? - kml

I am trying to update a KML file for a website that has a multiple locations and having some trouble. I want to use it accordance with schema.org to get rich snippets in Google search results. My problem is I can't find a solid answer on how to relate multiple listings to the proper pages.
I think I understand how to create the KML file from these resources.
https://developers.google.com/kml/documentation/kml_tut
http://sixrevisions.com/web-development/5-little-known-web-files-that-can-enhance-your-website/
Here is my example code:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<name>Hospital 1</name>
<description>Our first hospital</description>
<Style id="pin"><IconStyle><Icon><href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href></Icon></IconStyle></Style>
<Placemark>
<LookAt>
<longitude>-0.13642</longitude>
<latitude>50.819522</latitude>
<altitude>0</altitude>
<tilt>0</tilt>
<range>5500</range>
</LookAt>
<styleUrl>#pin</styleUrl>
<Point><coordinates>-0.13642,50.819522,0</coordinates></Point>
</Placemark>
</Document>
</kml>
I know that it has to be in the root folder and named after the site. But how do I name different locations or associate them to a certain page? Can I put the kml file on the different location pages?
I might be thinking about this in the wrong way so any help would be greatly appreciated.Thank you.

From your sixrevisions.com link, the part you are missing is that you have to reference this KML file on your webpage with a LINK tag:
<link rel="alternate" type="application/vnd.google-earth.kml+xml" href="SixRevisions.kml" />
The location and name of the file aren't important (as long as you update the href attribute). You can put this tag on whatever page you want so you can point each page at a separate file.

Related

Network Linked KML to a Folder of KMLs

Using the below format as starting point I would like to know how to solve the following problem. This is an example for a Root KML file that links to other KMLs. My problem is that people modifying sub1.kml might change the name from sub1.kml to sub1-05-OCT-16.kml or want to add another KML called sub1-a.kml. Once this occurs the network link is no longer valid. I can't link to a folder from what I have seen and I do not want o have to change this file everytime. Is there an esiaer solution I'm overlooking?
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<NetworkLink>
<name>NetworkLinked sub-item</name>
<Link>
<href> kml/sub1.kml </href>
</Link>
</NetworkLink>
<NetworkLink>
<name>NetworkLinked sub-item</name>
<Link>
<href> kml/sub2.kml </href>
</Link>
</NetworkLink>
</Document>
</kml>
A network link must point at a specific KML (or KMZ) file. Unfortunately there's no way to point it at a folder or directory and somehow get the list of files and pick out all the KML/KMZs. So you'll need to either make sure that the target file names stay the same, or update your NetworkLinks when they change.

Why is my NetworkLink not working inside a nested KMZ?

My problem is that I want to have a kmz file (nest1.kmz) nested within another kmz file (root.kmz) and also reference another nested .kml file (nest2.kml).
When I try to achieve this the network link that references the kml file does not load.
The top answer for Nesting KMZ files makes it seem like it should hopefully be possible, so am I doing something wrong here?
root.kmz >root.kml
>[nest1] >
>nest1.kmz >
>nest1.kml
>[nest2] >
>nest2.kml
The code for the 3 files is as follows:
root.kml
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>root.kmz</name>
<NetworkLink>
<name>nest1.kmz</name>
<Link>
<href>nest1/nest1.kmz</href>
</Link>
</NetworkLink>
</Document>
</kml>
nest1.kml
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>nest1.kmz</name>
<NetworkLink>
<name>nest2.kml</name>
<Link>
<href>nest2/nest2.kml</href>
</Link>
</NetworkLink>
<Placemark>
<Point>
<coordinates>175.589370309749,-39.5968230904137,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
nest2.kml
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>nest2.kml</name>
<Placemark>
<Point>
<coordinates>176.589370309749,-39.5968230904137,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
If you want a root KMZ file to reference other sub-KMZ files then the sub-KMZ files should not be sub-entries of the root KMZ file but located at the same relative context in the web server or file system.
Google Earth supports a large number of nested KML files within a KMZ file but does NOT support nested KMZ files within a parent KMZ file. Either layout the content as file structure where 1) all sub-kml files are within a single root.kmz file, or 2) sub-kmz files are co-located with the root kml or kmz file.
The file system or web server would have the following structures:
Structure 1:
root.kmz
nest1/nested1.kml
nest2/nested2.kml
Structure 2:
root.kmz
nest1/nested1.kmz
nest2/nested2.kmz
root.kmz can refer to nest1/nested1.kmz and nested1.kmz can then reference nested2.kmz.
Google Earth also supports sub-file references within a KMZ file so root.kmz could have a direct reference to nest2/nest2.kml if it is contained within nested1.kmz. That practice is not recommended since it may not be supported in applications other than Google Earth.
<Link>
<href>nested1.kmz/nest2/nested2.kml</href>
</Link>

How to create Google Earth KML network link that does not allow folder to be expanded

I have created a network link that references another KML file with actual data to be loaded into Google Earth. My issue is that the number of points in the referenced KML file is so large that it crashes Google Earth if the KML file folder underneath the Places tab in Google Earth is set to "Allow this folder to be expanded" (right-click KML, properties). By default, this checkbox is checked. I want to make it so that for every network link I create the folder by default will not be expandable.
I have looked up checkHideChildren in Google Earth KML tutorials, but that line provides no results, and I am not entirely sure where I am supposed to place the line in the Network Link KML.
Here is example code, if you could point me in the direction where to place this line of code, or an entirely different approach, it would be greatly appreciated!
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<NetworkLink>
<name>
CPU
</name>
<refreshVisibility>1</refreshVisibility>
<Link id="GPS_Plotter Updater">
<href>CPU.kml</href>
<Style id="style1"><ListStyle>
<listItemType>checkHideChildren</listItemType> <-- this is the line that should be hiding the children points of the KML!
</ListStyle>
</Style>
<styleUrl>#style1</styleUrl>
<refreshMode>onInterval</refreshMode>
<refreshInterval>1</refreshInterval>
<viewRefreshMode>onRegion</viewRefreshMode>
<viewRefreshTime>1</viewRefreshTime>
</Link>
</NetworkLink>
</kml>
Try putting the Style element in the NetworkLink, not the Link element. Link doesn't take a style selector, but NetworkLink does. If that doesn't work, try a listItemType of radioFolder instead.
In addition to Mano Marks' suggestions you also need to move the styleUrl element to the NetworkLink otherwise it won't apply. Note in your example you have viewRefreshMode=onRegion but don't have a region defined for it.
Here's the complete working example to suppress the NetworkLink contents.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<NetworkLink>
<name>CPU</name>
<styleUrl>#style1</styleUrl>
<Style id="style1">
<ListStyle>
<listItemType>checkHideChildren</listItemType>
</ListStyle>
</Style>
<Region>
<!-- define region here -->
</Region>
<refreshVisibility>1</refreshVisibility>
<Link id="GPS_Plotter_Updater">
<href>CPU.kml</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>1</refreshInterval>
<viewRefreshMode>onRegion</viewRefreshMode>
<viewRefreshTime>1</viewRefreshTime>
</Link>
</NetworkLink>
</kml>
You can catch errors like this by validating your KML. Try using the Galdos KML Validator.

Google Earth link PDF or image file on company server to placemark

I want to display multiple jpg(s) and/or pdf file(s) to a single placemark. The file path is in my company's directory and I would like anyone in the company that I send this google earth file to have the ability to view each placemark.
I have tried the command and neither seem to be working.
Both of these commands work with images at a "http:// address" but not with references to my hard drive nor server.
A KML Placemark can contain any number of images in its description. Most HTML will render inside the description of any given Placemark.
Option 1. Linking to a PDF or other media via URL within KML
Here's sample KML file to launch in Google Earth which will show an inline image in the popup balloon with a link to a PDF file:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<Placemark>
<name>Test</name>
<snippet/>
<description>
<![CDATA[<a href="http://stlab.adobe.com/wiki/images/d/d3/Test.pdf"><img
src="http://stlab.adobe.com/wiki/skins/common/images/icons/fileicon-pdf.png"></a>
]]>
</description>
<gx:balloonVisibility>1</gx:balloonVisibility>
</Placemark>
</kml>
Note the gx:balloonVisibility tag which if set to "1" will auto-display the popup. That's a useful feature.
If images are within your hard-drive then you won't be able to share the KML with others unless you either bundle the images inside a KMZ file or publish the images to web site in your company so they are accessible via a URL.
Option 2. Embed the PDF within the Placemark description balloon
One trick to directly embed the PDF within the Placemark description balloon is using the Google PDF viewer in an iframe and substitute the test URL for actual URL in link below.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>Test</name>
<snippet/>
<description>
<![CDATA[
<iframe src="http://docs.google.com/gview?url=http://stlab.adobe.com/wiki/images/d/d3/Test.pdf&embedded=true"
style="width:718px; height:700px;" frameborder="0"></iframe>
]]>
</description>
</Placemark>
</kml>
This technique doesn't need a Flash player and works in Google Earth.
Note if you do this too many times and/or try for very large documents then the viewer will display the message:
You've reached the bandwidth limit for viewing or downloading files that aren't in Google Docs format. Please try again later.

KML Network Link - Fly To

I am developing an application that launches Google Earth with a KML file that links to other local files via <NetworkLink>, which does Time Interval refreshing. I'm trying to define a KML file that will center the map (fly to) a specific location.
Network Link has a tag which flies to the first placemark or FlyTo within the file. However, this would execute the fly to whenever the file is refreshed, which in my case, is when the Time Interval expires. Is there some way that I can have the fly-to command execute only when the linked network file changes, rather than every time? Is there any way to have the Fly To process only once until the linked file is changed somehow? My NetworkLink file is defined as follows:
<NetworkLink>
<name>My Fly To Request</name>
<Link>
<href>MyFlyTo.kmz</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>2</refreshInterval>
</Link>
</NetworkLink>
The application will frequently update the the specific placemark to be centered on when the user requests. It is not a static placemark that needs to be centered on, but one that will change frequently.
I believe you could achieve this by using a combination of ID attributes and the NetworkLinkControl and Update element in Kml.
The MyFlyToRequest.kml file contains the NetworkLink that loads the data file, which contains your data, it has the flyToView element set to true. Notice too the network link also has an id of request
MyFlyToRequest.kml
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<NetworkLink id="request">
<name>My Fly To Request</name>
<Link>
<href>http://www.yourserver.com/MyFlyTo.kmz</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>2</refreshInterval>
</Link>
<flyToView>1</flyToView>
</NetworkLink>
</kml>
The second file, MyFlyTo.kmz, is the one loaded. It has your current data as is..,However, it would also have an additional NetworkLink that loads a new third file.
MyFlyTo.kmz - Edited
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="data">
<visibility>1</visibility>
<NetworkLink>
<name>Update MyFlyToRequest</name>
<Link>
<href>http://www.yourserver.com/TurnOffFlyTo.kml</href>
</Link>
</NetworkLink>
<Placemark>
<name>This is flown to once (hopefully)</name>
<Point>
<coordinates>52,0,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
The new third file TurnOffFlyTo.kml is part of the key to the set up, it contains a NetworkLinkControl that targets the request NetworkLink in the first MyFlyToRequest.kml file. It simply sets flyToView element to 0.
TurnOffFlyTo.kml
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<NetworkLinkControl>
<Update>
<targetHref>http://www.yourserver.com/MyFlyToRequest.kml#request</targetHref>
<Change>
<NetworkLink id="request">
<!-- turn off the flyto behaviour -->
<flyToView>0</flyToView>
</NetworkLink>
</Change>
</Update>
</NetworkLinkControl>
</kml>
The final file TurnOnFlyTo.kml simply retoggles the flyto behaviour again.
TurnOnFlyTo.kml
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<NetworkLinkControl>
<Update>
<targetHref>http://www.yourserver.com/MyFlyToRequest.kml#request</targetHref>
<Change>
<NetworkLink id="request">
<!-- turn off the flyto behaviour -->
<flyToView>1</flyToView>
</NetworkLink>
</Change>
</Update>
</NetworkLinkControl>
</kml>
The logic is as follows.
MyFlyToRequest.kml loads MyFlyTo.kml
flyto is enabled so the view moves the first first placemark, etc, in MyFlyTo.kml
The link in MyFlyTo.kml loads TurnOffFlyTo.kml.
The Update in TurnOffFlyTo.kml three disables flyto in MyFlyToRequest.kml.
File one, refreshes, loads file two...
If you need to re-enable the flyto, you would simply load File four. If the data in MyFlyTo.kmz is being generated by you it would be a simple case of loading TurnOnFlyTo.kml right where TurnOffFlyTo.kml was called.
All that said, this is not tested and as such might not work as is, although in principal I don't see why it wouldn't.
If it sounds like something you might try here are a few resources that should help.
NetworkLinkControl Reference
http://code.google.com/apis/kml/documentation/kmlreference.html#networklinkcontrol
Using Updates
http://code.google.com/apis/kml/documentation/updates.html

Resources