A KML Sitemap

This post assumes basic understand of website structures and XML documents.

After finishing my adventure map (map.jacobemerick.com) a few weeks ago, I wanted to share the KML information online for people using Google Earth or Google Maps. A KML document is merely an XML document with special tags and data that is related to mapping - it includes latitudes, longitudes, and descriptions of geographical points. My adventure map parses KML documents to display the routes, photos, and points viewable on the map. However, in order to offer these KMLs in a way that search robots could view them, I had to do some modifications.

The first step was making sure that my KML documents were being read as KMLs. All of them are generated from a single PHP script, called processor.php, and I wanted to give them a content-type so that programs, including search robots, understood that it was a KML document. This was easy to add in my PHP document.

  1. echo header('Content-type:Application/vnd.google-earth.kml+xml');

Since I have a large number of KML documents being generated by my script, I added this line in front of the document types that I wanted to be indexed and understood by programs. Even though the script still runs as a php document, the output will be interpreted as a KML document. If you have normal KMLs on your site, this step is not necessary.

The next step is to create your sitemap. This is merely an XML document that contains all of your web page urls. Normally, it would look like this...

  1. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

  2. <url>

  3. <loc>https://map.jacobemerick.com/</loc>

  4. <lastmod>2009-07-16</lastmod>

  5. <priority>1.0</priority>

  6. <changefreq>monthly</changefreq>

  7. </url>

  8. </urlset>

Each page has its own url, with a loc, lastmod, priority, and changefreq. Some of these are optional, but I'd recommend including at these three. For more information about these fields and values, just visit the Sitemaps site.

To add KMLs to this for programs to find, you first have to add a new schema in the opening tag. After this, you just tag the url as a KML document, and you're set. So, if I add a KML to the above sitemap, it would look like this...

  1. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:geo="http://www.google.com/geo/schemas/sitemap/1.0">

  2. <url>

  3. <loc>https://map.jacobemerick.com/</loc>

  4. <lastmod>2009-07-16</lastmod>

  5. <priority>1.0</priority>

  6. <changefreq>monthly</changefreq>

  7. </url>

  8. <url>

  9. <loc>https://map.jacobemerick.com/?hike=Yellow+Dog+Falls</loc>

  10. <lastmod>2009-07-16</lastmod>

  11. <priority>0.2</priority>

  12. <changefreq>never</changefreq>

  13. <geo:geo>

  14. <geo:format>kml</geo:format>

  15. </geo:geo>

  16. </url>

Now my map website has a low priority KML that shows the Yellow Dog Falls. That's all there is to it!