Skip to content

Instantly share code, notes, and snippets.

@emperorcezar
Created June 17, 2011 12:17
Show Gist options
  • Save emperorcezar/1031306 to your computer and use it in GitHub Desktop.
Save emperorcezar/1031306 to your computer and use it in GitHub Desktop.
Quick library for Google Place API
import urllib2
import simplejson
class GPlaces(object):
def __init__(self, key):
self.key = key
self.search_url = "https://maps.googleapis.com/maps/api/place/search/json"
def search(self, location, radius, sensor, **kwargs):
# Build the url
parameters = []
for key, value in kwargs.items():
parameters.append("%s=%s" %(key, value))
parameters.append("location=%s" %(location,))
parameters.append("radius=%s" %(radius,))
parameters.append("sensor=%s" %(sensor,))
parameters.append("key=%s" %(self.key,))
parameters_string = '&'.join(parameters)
url = "%s?%s" %(self.search_url, parameters_string)
request = urllib2.Request(url, None, {'Referer': "http://localhost"})
response = urllib2.urlopen(request)
# Process the JSON string.
results = simplejson.load(response)
# now have some fun with the results...
print results
if __name__ == '__main__':
api = GPlaces("YOURKEYHERE")
api.search("41.526143699999999,-87.889218900000003", "1000", "false")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment