Created
January 19, 2014 19:42
-
-
Save svschannak/8509994 to your computer and use it in GitHub Desktop.
Get the name of the city and the street of your location from Google Geocode. Example for Django.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_city_json(request, latitude, longitude): | |
r = requests.get('http://maps.googleapis.com/maps/api/geocode/json?latlng=%s,%s&sensor=true' % (latitude, longitude)) | |
#convert result to json | |
json_data = r.json() | |
#get data from json | |
city = json_data['results'][0]['address_components'][3]['long_name'] | |
response_data = {} | |
response_data['city'] = city | |
response_data['street'] = json_data['results'][0]['address_components'][1]['long_name'] | |
#data as json-response | |
return HttpResponse(json.dumps(response_data), content_type="application/json") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment