Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding in a file to illustrate minimal geocoding legwork

  • Loading branch information...
commit 2fcf6f31176018a32449ba2bfa8103b68fa4d3f4 1 parent 9dd1eaf
@ptwobrussell authored Matthew Russell committed
Showing with 29 additions and 0 deletions.
  1. +29 −0 etc/geocoding_pattern.py
View
29 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)
Please sign in to comment.
Something went wrong with that request. Please try again.