Export My Map as KML

· Introduction

A number of people want to export their data from "My Maps", and Google provide a KML export. However there is a common gotcha when attempting it, so thought would post it here. 

(Note that since this page was first published, Google have added a direct KML link to the download, so its much easier now!) 

· Restrictions

There are however a number of limitations with the export:
  1. 'Snap to Roads' lines; the export only includes the user entered points, not the actual road following line. 
  2. 'Search Results' - Results saved to "My Maps" via the 'Save to' feature - only export the title, not the description

· The short version

View your map, and the click the "KML" link. This link downloads the actual data - whoop!

(Don't use the  View in Google Earth icon - that only downloads a link - see below) 

· Alternative version

This application: 
http://maps-data-liberation.appspot.com/ gives you quick links to the KML files for your "My Maps" (and at the same time will offer to save a copy to Fusion Tables. 

· The longer version

The View in Google Earth icon
 rightly produces a KML file, which when loaded up in Google Earth displays your map, great! However this KML file you download is a "Network Link" or pointer to another URL. This is done so that as you update the map on Google Maps, Google Earth can actully refetch the content so that changes are visible. But this makes the KML file not very useful for getting the actual data. 

If you view the file it looks something like this:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
  <name>Example points in UK</name>
  <description><![CDATA[]]></description>
  <NetworkLink>
    <name>Example points in UK</name>
    <Link>
      <href>http://maps.google.co.uk/maps/ms?ie=UTF8&amp;hl=en&amp;oe=UTF8&amp;msa=0&amp;msid=103387750622659154041.00045e6c12a1cc165d6ee&amp;output=kml</href>
    </Link>
  </NetworkLink>
</Document>
</kml>

And there is the link, which notice contains output=kml - to get the actual data. Google Earth knows to follow the network link to get the content, and now you do too!

A word of warning tho
, notice in the URL the &amp;'s, because the above file is actully XML the & in the url needs to be entity encoded, so if copy/pasting (or scripting!) you need to make sure you also decode. A XML parser might do it for you but you still might need to do it, in PHP html_entity_decode is useful. 

So the above link actually becomes: 

http://maps.google.co.uk/maps/ms?ie=UTF8&hl=en&oe=UTF8&msa=0&msid=103387750622659154041.00045e6c12a1cc165d6ee&output=kml

(which is just a slight variation on the link you get if you just change the 'View in Google Earth' url, mentioned in the shortcut) 


· RSS alternative!

This feature is no longer available



Comments