October 9, 2006

GPS + Google Maps Mash-up in 42 lines of code


Here is a quick and dirty hack to perform mobile GPS-referenced Google Map searches on your laptop (e.g., where's the next coffee shop around here?). 42 lines, about half of them comments. I put this small demo together for last weekend's Silicon Valley Code Camp to show how easy it is to get up and running with GPS. Reading the latitude/longitude from the GPS device takes no work at all, most of the code is just concerned with converting the coordinates into the right number format for Google Maps, and finding the web browser on your machine.

Hardware: you'll need a GPS unit that can output data in NMEA format (most do) and some way to connect it to your laptop. I've tested both the el-cheapo Pharos 360, rebranded by Microsoft and distributed in their Streets+Trips package, and the Trimble Lassen IQ USB Eval Kit sold by SparkFun. Both connect via USB and come with a virtual COM port driver. This means that in your code, you can connect to these devices as if they are connected to a regular serial port.

Software: The example is written in Python 2.4 with the pySerial extension for serial communication installed. On Windows, you'll also need pywin32.

View source in HTML
Download source: gps.zip

Posted by Bjoern Hartmann at October 9, 2006 10:03 PM