Jessica Lord, open web developer—designer

KML from Google Maps

  • By Jessica Lord
  • 2015-04-26
  • maps, web dev

I wanted to make a map of a little trek I did to Rivendell in New Zealand (NBD!). Here is what I learned about getting map data out of Google Maps (KML) to create a Mapbox map.

Map of train, bus, walking and hiking from Wellington to Kaitoke and Rivendell in Wellington, NZ

Mapbox makes great software and beautiful maps (see above!). This is why I didn't attempt to just do the whole thing in Google Maps. I used Mapbox's online map making tool, Editor, which accepts kml, the format that Google Maps use. However:

You cannot export kml from regular

I learned that the only way to export kml from Google Maps was to log in and create a map in the My Maps option. However:

The maps in My Maps do not support transit directions.

Which was a bummer because I was wanting to include the train and bus routes in my map. Fortunately the bus route was relatively simple so I opened it in Google Maps in one tab and then drew the route in My Maps by drawing lines that snap to roads (lines don't snap to roads in Mapbox Editor). I drew the train route with straight lines directly in Mapbox Editor.

Next, I selected to export as kml. Then selected the layer I wanted to export.


At this point you'll see that you actually get a compressed kmz rather than kml. You'll need to do a few things in order to get at that kml. Change the kmz extension to 'zip' and unzip it. Inside you'll find a few files. You can do this via terminal:

# copy it as a zip file, keeping original just in case
cp downloadedMap.kml
# unzip it
# rename it, if you want
mv doc.kml myMap.kml

Now you have a couple image files and a doc.kml. The latter is the kml you want. You may want to rename it at this point (especially if you're doing this multiple times) and trash the images. Now you can import this kml into Mapbox Editor and style it, hurray!


I also ended up using the Google My Maps to trace a path from satellite images because the Mapbox tiles didn't zoom in as close as I wanted. There was a lot of trial and error in my discovering each of these things and the map took way longer than it should have, so I hope this helps someone else!

Let me know if there are better ways of getting data from transit directions, snap-to-road lines and good satellite imagery (@jllord).