Navigation Menu

Skip to content

Commit

Permalink
Adding in a file to illustrate minimal geocoding legwork
Browse files Browse the repository at this point in the history
  • Loading branch information
ptwobrussell authored and Matthew Russell committed Apr 19, 2011
1 parent 9dd1eaf commit 2fcf6f3
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions etc/geocoding_pattern.py
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-

# A simple pattern created to illustrate geocoding for Where 2.0 (2011)
# Get your Google Maps API Key from http://code.google.com/apis/maps/signup.html

import geopy
GOOGLE_MAPS_API_KEY = ''
g = geopy.geocoders.Google(GOOGLE_MAPS_API_KEY)


transforms = [('Greater ', ''),
(' Area', ''),
('San Francisco Bay', 'San Francisco')] # etc.

locations = ['Greater Nashville Area',
'San Francisco Bay'] # from LinkedIn data

cache = {}
for location in locations:
if cache.has_key(location): # Preserve API calls
continue

for transform in transforms:
results = g.geocode(location, exactly_one=False)
cache[location] = [r for r in results][0][1]
break

import json
print json.dumps(cache, indent=2)

0 comments on commit 2fcf6f3

Please sign in to comment.