
297 - CREATE GOOGLE MAPS OVERLAYS ON THE FLY
HaCK
# 121
HaCK 121:
A little MySQL and Python puts your locations on the map: you can
generate a KML le dynamically with the latest and greatest data.
KML, the Keyhole Markup Language, can be used to describe locations in Google Earth. It’s an XML
format that Google Maps supports too. You can, for instance, paste the URL of any KML le into the
Google Maps search box and hit return; seconds later, the placemarks appear on the map (the same
is true for KMZ les, which are zipped KML les).
If you’ve got geographical data is stored in a database such as MySQL, dropping it on Google
Maps won’t be a problem. In this hack, I’m using Python to turn a database table into a KML le. To
implement this hack, you’ll need:
Some experience with Python and MySQL.
Your own MySQL server on which you can create tables.
A recent version of Python, with the MySQLdb and Minidom modules installed (if you don’t
have Minidom, go to http://pyxml.sourceforge.net).
The database table, which is named places, has the following data denition. Feed this into MySQL,
or whichever database you are using, to create it:
CREATE TABLE placemarks
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
description VARCHAR(255),
latitude DOUBLE,
longitude DOUBLE);
1.
2.
3.
Google Sky, as part o ...