-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcity_demo.py
More file actions
26 lines (22 loc) · 719 Bytes
/
city_demo.py
File metadata and controls
26 lines (22 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from urllib2 import urlopen
import json
components=''
def getplace(lat, lon):
url = "http://maps.googleapis.com/maps/api/geocode/json?"
url += "latlng=%s,%s&sensor=false" % (lat, lon)
v = urlopen(url).read()
j = json.loads(v)
#print j['results'][0]['address_components']
components = j['results'][0]['address_components']
country = town = None
for c in components:
if "country" in c['types']:
country = c['long_name']
if "postal_town" in c['types']:
town = c['long_name']
return str(town), str(country)
#print components
print getplace(52.1, 11.1)
a, b = getplace(51.1, 0.1)
print a, b
print getplace(52.1, 10.1)