Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Export Google Maps starred locations
# -*- coding: utf-8 -*-
Go to Google Bookmarks:
On the bottom left, click "Export bookmarks":
After downloading the html file, run this script on it to generate a KML.
from lxml.html import document_fromstring
import simplekml
from urllib2 import urlopen
import re
import time
filename = r'GoogleBookmarks.html'
with open(filename) as bookmarks_file:
data =
kml = simplekml.Kml()
# Hacky and doesn't work for all of the stars:
lat_re = re.compile('markers:[^\]]*latlng[^}]*lat:([^,]*)')
lon_re = re.compile('markers:[^\]]*latlng[^}]*lng:([^}]*)')
coords_in_url = re.compile('\?q=(-?\d{,3}\.\d*),\s*(-?\d{,3}\.\d*)')
doc = document_fromstring(data)
for element, attribute, url, pos in doc.body.iterlinks():
if '' in url:
description = element.text or ''
print description.encode('UTF8')
print u"URL: {0}".format(url)
# Coordinates are in URL itself
latitude =[0]
longitude =[1]
# Load map and find coordinates in source of page
sock = urlopen(url.replace(' ','+').encode('UTF8'))
except Exception, e:
print 'Connection problem:'
print repr(e)
print 'Waiting 2 minutes and trying again'
sock = urlopen(url.replace(' ','+').encode('UTF8'))
content =
time.sleep(3) # Don't annoy server
latitude = lat_re.findall(content)[0]
longitude = lon_re.findall(content)[0]
except IndexError:
print '[Coordinates not found]'
print latitude, longitude
coords=[(float(longitude), float(latitude))])
except ValueError:
print '[Invalid coordinates]'

marado commented Aug 15, 2014

I'm using (part of) this at . I am assuming I can, since there's no LICENSE information for this gist, but I wouldn't mind getting explicit permission.


endolith commented Sep 25, 2014

You have explicit permission! :)

How do you run the html file in KML? I did get all the names of my bookmarks (thank you for that)

iturki commented Dec 28, 2015

Or, you can use this online tool to do the html > KML conversion:

jbg commented Apr 5, 2016

I made a Python 3, GeoJSON-exporting version based on this script here:

ngzhian commented Jun 28, 2016

I updated the regex for lat, lng based on the most recent google response, here's the gist:

3v1n0 commented Jan 11, 2017

Thanks, I guess you want to merge changes from @ngzhian in order to get this working properly with new APIs

heyarne commented Jan 29, 2017

Hey! Just a quick heads up: I packaged it up a bit with a proper requirements.txt and put it up on I hope that's fine. If it's ok i'd also like to build a simple web interface around it, but because of the missing license file I didn't want to do it without permission. Any objections?

I've made another script that converts Google Maps JSON to KML. It is more complete and it works flawless! Check here:

LaDeeDaDee commented Mar 3, 2017

@dmrsouza flawless if you know can run simplekml via a pip...

'pip' is not recognized as an internal or external command,
operable program or batch file.

How do I install simplekml via pip? I have downloaded simplekml 1.3.0 but I'm not sure if it is installed?

dmrsouza commented Mar 4, 2017

@LaDeeDaDee At least on Windows pip command is installed with Python. Anyway there are instructions about how to install pip at

I am a beginner with python, but managed to get through the installation, pip.. now I'm stuck here:

Opening file "Saved Places.json"
Traceback (most recent call last):
File "C:\Users\Kierownik\Desktop\json2kml\", line 32, in
for place in data["features"]:
KeyError: 'features'

Would you, please, be able to help?


@rlewandowski1988, please check your JSON file (open it in a text editor). It should start as:

{ "type" : "FeatureCollection", "features" : [ { "geometry" : { "coordinates" :........

It seems it is missing the "features" section. If your data is not private and if you can share your JSON file, I am willing to help you.

@dmrsouza, I previously gave up becaue I realised that google introduced new feature under saving your places - now you can save and give the location one of the categories: Favorites, Want to go, Starred places or New list (you create one). Knowing that I just thought that they probably changed the data structure and that's why stopped working... but it turned out that insted of downloading Maps (your places) I downloaded the Location history ;) Nevertheless your comment helped! thanks very much for help! all the very best! ;)

blaines commented Jul 26, 2017

Google says "No Data Found" for all of my accounts when exporting "Maps (your places)". Boo

Trying the bookmarks approach instead

andriip commented Aug 4, 2017

@rlewandowski1988, Hi did you try this script with your Location History file?
Is it working?

YvesBas commented Nov 1, 2017

Thanks for this very useful script! However I would need to get also the custom labels I added to my starred locations to be able to use this data on another GIS. Do you think it would be possible to get the labels??

eszjay commented Dec 4, 2017

Google has now provided their own tool to export your Map data in JSON format at Google Takeout

@heyarne I tried using your script as it's exactly what I need in my situation ( don't have access to old account but downloaded the HTML file), but I got this error 'No module named simplekml '
I tried installing simplekml with pip install simplekmp, but got the following error-

Any help would be appreciated, I'm a super noob here...but could really use all my 1000s of bookmarks in the new account...

Collecting simplekml
Using cached
Installing collected packages: simplekml
Running install for simplekml ... error
Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;file='/private/var/folders/jk/6y47vn0d2gdcd9v84g51zz8h0000gn/T/pip-build-Vgk14q/simplekml/';f=getattr(tokenize, 'open', open)(file);'\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /var/folders/jk/6y47vn0d2gdcd9v84g51zz8h0000gn/T/pip-ZB2nDK-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
copying simplekml/ -> build/lib/simplekml
copying simplekml/ -> build/lib/simplekml
running install_lib
creating /Library/Python/2.7/site-packages/simplekml
error: could not create '/Library/Python/2.7/site-packages/simplekml': Permission denied

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment