3 nominatim.openstreetmap.org API
9 def GetXMLDescr(lat,lon):
11 req = urllib2.Request("http://nominatim.openstreetmap.org/reverse?lat=%s&lon=%s&accept-language=ru,en" %(lat,lon), None)
12 page = urllib2.urlopen(req).read()
14 return etree.fromstring(page)
16 def printable_name(addr):
20 if addr['country'] == u"Российская Федерация" and addr['state'] == u"Москва":
22 str = addr['road'] + ', ' + addr['state'] + ', ' + addr['country']
24 str = addr['state'] + ', ' + addr['country']
28 str = addr['road'] + ', ' + addr['city'] + ', ' + addr['state'] + ', ' + addr['country']
30 str = addr['city'] + ', ' + addr['state'] + ', ' + addr['country']
33 str = addr['road'] + ', ' + addr['town'] + ', ' + addr['state'] + ', ' + addr['country']
35 str = addr['town'] + ', ' + addr['state'] + ', ' + addr['country']
36 elif 'village' in addr:
38 str = addr['road'] + ', ' + addr['village'] + ', ' + addr['state'] + ', ' + addr['country']
40 str = addr['village'] + ', ' + addr['state'] + ', ' + addr['country']
41 elif 'county' in addr:
43 str = addr['road'] + ', ' + addr['county'] + ', ' + addr['state'] + ', ' + addr['country']
45 str = addr['county'] + ', ' + addr['state'] + ', ' + addr['country']
48 str = addr['road'] + ', ' + addr['state'] + ', ' + addr['country']
50 str = addr['state'] + ', ' + addr['country']
54 str = addr['road'] + ', ' + addr['city'] + addr['country']
56 str = addr['city'] + ', ' + addr['country']
57 elif 'village' in addr:
59 str = addr['road'] + ', ' + addr['village'] + addr['country']
61 str = addr['village'] + ', ' + addr['country']
64 str = addr['road'] + ', ' + addr['country']
68 str = u"Планета Земля, "
70 str = str + u"%s с.ш.," % (addr['lat'])
72 str = str + u"%s ю.ш.," % (-addr['lat'])
74 str = str + u"%s в.д." % (addr['lon'])
76 str = str + u"%s з.д." % (-addr['lon'])
82 def __init__(self, lat, lon):
84 for elem in GetXMLDescr(lat,lon):
85 self.addr = {'lat':lat,'lon':lon}
90 if elem.tag == "addressparts":
93 text = urllib2.unquote(addrpart.text)
99 elif tag == "country":
102 self.printable = printable_name(self.addr)