So this is something that’s been bugging me for a while now. At the City of Lincoln Council I promote not only the use of web based tools such as those that Google supply, but also the use of open data. To that, I created the site data.lincoln.gov.uk, a WordPress powered site which pushes out Lincoln data sets in a nice, easey, machine readable way. CSV, RDF – those boxes got ticked early on. But KML was eluding me. We create most of our maps by hand in Google maps. Now, I know that this produces KML – it can be used in Google Earth, there’s a link for it and all. But downloading the “KML” file from this link produces what looks like a simple hook in for Google Earth to retrieve the online KML data.

Humm.

Let’s take a look at the problem. We’ll use this map here for reference. The url from the “Download to Google Earth” button (which you can get by right clicking on the button) defaults to this:

http://www.google.co.uk/maps/ms?ie=UTF8&hl=en&vps=1&jsv=280a&msa=0&output=nl&msid=100185268874394349858.000459d5fe17d48f39f66

This gives us our KML file that hooks into Google Earth; great for that use, not so good for my data site! Take a look at the url – see that bit that says “output = nl”? Let’s change that to “output=kml”. That gives us the link:

http://www.google.co.uk/maps/ms?ie=UTF8&hl=en&vps=1&jsv=280a&msa=0&output=kml&msid=100185268874394349858.000459d5fe17d48f39f66

…which produces EXACTLY what we want – the makeup of the map in raw KML. Spiffing! I can’t take credit from that – this article helped me out.

What I have done, however, is take it further. how can we engineer this to get the KML of any map? The key is in the msid part. This is what Google uses to identify a map. In the map, click on the “Link” button and take a look at the link. The msid is encoded in there. Simply replace the msid in the link above with the msid of the map you want the KML for and you’re away!

Job done!

Hopefully that’s all clear and of some use to you! I’m off to convert all of our maps to KML links so that we can provide them on our data site! Ta ta!

Advertisements