Geocoding UK addresses

380 views
Skip to first unread message

Brian Beck

unread,
Sep 9, 2006, 4:35:36 PM9/9/06
to geopy
Norman Khine and I have been looking into geocoding UK address with
geopy.

The reason it doesn't work with the Google geocoder is explained in
this thread:
http://groups.google.com/group/Google-Maps-API/browse_thread/thread/c3f8b0c83e2b8c99/c9ff193615d0ebb4

So apparently due to contractual reasons, Google can't offer UK
addresses through their HTTP geocoder.

The localsearchmaps.com geocoder has an API that can geocode UK
addresses. However, it is merely an aggregate of Google Maps and
Virtual Earth data (which is in geopy now, BTW), so I don't really want
to add it to geopy. Plus it expects you to parse your location string
first.

However, I just spent a while reverse-engineering the Google Maps
interface to see if I can just use that data, since Google Maps has no
problem finding UK addresses. This also works without an API key. The
result is currently in trunk, so that you can now do this:

from geopy.geocoders import Google
g = Google(resource='maps')
g.geocode('London, UK')

This would have formerly returned 0 results.

To get specific addresses in the UK, you have to be a little more
specific:

g = Google(domain='maps.google.co.uk', resource='maps',
output_format='js')

output_format can either be 'js' or 'kml' (the default). 'js' currently
works better for finding addresses in the UK, 'kml' has a tendency to
return street locations instead of building locations on the street,
but it's the default since it works for both the 'maps' (Google Maps
interface) and 'maps/geo' (Google HTTP geocoder) resource. They both
have a tendency to return multiple locations, so you'll want to use
exactly_one=False:

g.geocode('48 Leicester Square, London UK', exactly_one=False).next()
('48 Leicester Square, London, WC2H 7LT', (51.510120999999998,
-0.131019))

Any help with testing or further reverse-engineering is welcome. Happy
geocoding!

--
Brian Beck
Adventurer of the First Order

walweb.nl

unread,
Sep 12, 2006, 4:55:22 AM9/12/06
to geopy
Lookup your place by address
Check this out:
www.walweb.nl/picsfromspace
Reply all
Reply to author
Forward
0 new messages