-
-
Save damiann/8427619 to your computer and use it in GitHub Desktop.
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
#!/usr/local/bin/python2.7 | |
import urllib2, json | |
def get_coorinates(request): | |
eat_all = Eat.objects.all().values() | |
for eat in eat_all: | |
obj = Eat.objects.filter(id=eat['id'])[0] | |
address = obj.address.replace(" ", "+") | |
url = "".join(["http://maps.googleapis.com/maps/api/geocode/json?address=", address, "&sensor=false"]); | |
response = urllib2.urlopen(url); | |
data = json.loads(response.read()) | |
result = data.get("results",{}) | |
geometry = [ geometry['geometry'] for geometry in result ] | |
location = [ location['location'] for location in geometry ] | |
for x in location: | |
obj.lat_coordinates = str(x['lat']) | |
obj.lng_coordinates = str(x['lng']) | |
print obj | |
obj.save() | |
return HttpResponse({'success': True},content_type='application/json') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment