Skip to content

Instantly share code, notes, and snippets.

@joannecheng
Created October 2, 2013 20:36
Show Gist options
  • Save joannecheng/6800144 to your computer and use it in GitHub Desktop.
Save joannecheng/6800144 to your computer and use it in GitHub Desktop.
Google Places exporter. Pass in lat/lng increment, bounding coordinates, search_query. Queries the google places API and exports csv with closest distance to the place that matches your search query.
GOOGLE_API_KEY = os.environ.get('GOOGLE_API_KEY')
class GooglePlacesExporter:
column_headers = ['lat', 'lng', 'latnear', 'lngnear', 'dist_miles']
def __init__(self, lat_incr=-0.29, lng_incr=0.29, search_query='grocery_or_supermarket', lat_NW=49.44098806129775,lng_NW=-127.13476612499217, lat_SE=23.725012, lng_SE=-61.347656):
self.lat_incr = lat_incr
self.lng_incr = lng_incr
self.lat_curr = lat_NW
self.lng_curr = lng_NW
# Bounding box
self.lat_NW = lat_NW
self.lng_NW = lng_NW
self.lat_SE = lat_SE
self.lng_SE = lng_SE
self.rows = []
self.google_url = "https://maps.googleapis.com/maps/api/place/search/json"
self.google_url_params_string = '?%(location)s&sensor=false&key='+GOOGLE_API_KEY+'&%(radius)s&types='+search_query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment