Geocoding in Python
Posted 21 Nov 2005 by herman

For your homework, this may be useful.

According to this article, geocoding in Python can be as simple as this:

import xmlrpclib
geocode_url = ''
p = xmlrpclib.ServerProxy(geocode_url)
address = "100 South Dubuque Street, Iowa City, IA"
result = p.geocode(address)
print result
I tried this, and it does work for many cases, though I didn't explore it completely. Here's an example: Try putting in '100 South Dubuque Street, 52240' and you should see a result. To view the source of this example, look in directory geocode-doc (you may need to view source when looking at the googleHead.html file).

Python Wierdness

In developing this example, I was frustrated by Python when I tried to convert a longitude (which was a floating point number) to a string: I tried just to use something like str(longitude), which should invoke Python's built-in 'str' function to do the conversion -- this works for int, float, list, and so on. But it failed and gave me some strange error message! The problem turned out to be (and you can see this in the maplish directory of the ta) that I had named a variable 'str' -- and this confused Python. Probably it's a good idea to stay away from names that conflict with Python's builtins.

Home PageHelp PageView ArticlesView Public DocumentsLogin, do stuff (record diaries)List Group MembersList of Projects