“Where Am I?” on a Nokia N95 in 8 lines of Python

April 10th, 2008 by Peter Rukavina

PyS60 on a Nokia N95

The Nokia N95 mobile phone is tailor-made for experimenting with Plazes: it has an internal GPS, Bluetooth, wifi, and can run Python. What more could you ask for in a location-based hacking device?

Here’s an 8-line proof-of-concept script that shows how you can use the internal GPS along with the new Plazes.net feature that lets you find Plazes near a latitude and longitude.

To use this you’ll need:

You need sign PythonScriptShell and LocationRequestor with SymbianSigned.com before you install them.

Once everything is installed, your GPS can see the sky, and you’re within range of a wifi access point, you can use this code to find the nearest Plaze to your current GPS location:

import httplib,locationrequestor
lr = locationrequestor.LocationRequestor()
lr.Open(lr.GetDefaultModuleId())
pos = lr.NotifyPositionUpdate()
connection = httplib.HTTPConnection('plazes.net:80')
connection.request("GET","/plazes.xml?near=" + str(pos[1]) + “,” + str(pos[2]) + “&limit=1″)
response = connection.getresponse()
print response.read()

Note that this is the most stripped-down possible way to do this; a real production script would build in error correction (is the GPS there? did I connect to wifi?). But if all the planets are aligned when you run it, you should get back the XML describing the nearest Plaze (change the limit=X if you want to retrieve more Plazes).

If you’re interested in exploring the combination of Python, S60 and Plazes, be sure to check out PythonS60Plazer from Tom Hughes-Croucher and Nick Burch’s excellent collection of scripts.

Leave a Reply