3 nominatim.openstreetmap.org API
9 def GetXMLDescr(lat,lon):
11 reqstr = "http://nominatim.openstreetmap.org/reverse?lat=%s&lon=%s&accept-language=ru,en" %(lat,lon)
13 headers = { 'User-Agent' : 'PyRunGPS/1.0', 'Referer' : 'https://maps.rvb.name' }
14 req = urllib2.Request(reqstr, None, headers)
15 page = urllib2.urlopen(req).read()
17 return etree.fromstring(page)
19 def printable_name(addr):
23 if addr['country'] == u"Российская Федерация" and addr['state'] == u"Москва":
25 str = addr['road'] + ', ' + addr['state'] + ', ' + addr['country']
27 str = addr['state'] + ', ' + addr['country']
31 str = addr['road'] + ', ' + addr['city'] + ', ' + addr['state'] + ', ' + addr['country']
33 str = addr['city'] + ', ' + addr['state'] + ', ' + addr['country']
36 str = addr['road'] + ', ' + addr['town'] + ', ' + addr['state'] + ', ' + addr['country']
38 str = addr['town'] + ', ' + addr['state'] + ', ' + addr['country']
39 elif 'village' in addr:
41 str = addr['road'] + ', ' + addr['village'] + ', ' + addr['state'] + ', ' + addr['country']
43 str = addr['village'] + ', ' + addr['state'] + ', ' + addr['country']
44 elif 'county' in addr:
46 str = addr['road'] + ', ' + addr['county'] + ', ' + addr['state'] + ', ' + addr['country']
48 str = addr['county'] + ', ' + addr['state'] + ', ' + addr['country']
51 str = addr['road'] + ', ' + addr['state'] + ', ' + addr['country']
53 str = addr['state'] + ', ' + addr['country']
57 str = addr['road'] + ', ' + addr['city'] + ', ' + addr['country']
59 str = addr['city'] + ', ' + addr['country']
60 elif 'village' in addr:
62 str = addr['road'] + ', ' + addr['village'] +', ' + addr['country']
64 str = addr['village'] + ', ' + addr['country']
67 str = addr['road'] + ', ' + addr['country']
71 str = u"Планета Земля, "
73 str = str + u"%s с.ш.," % (addr['lat'])
75 str = str + u"%s ю.ш.," % (-addr['lat'])
77 str = str + u"%s в.д." % (addr['lon'])
79 str = str + u"%s з.д." % (-addr['lon'])
85 def __init__(self, lat, lon):
87 for elem in GetXMLDescr(lat,lon):
88 self.addr = {'lat':lat,'lon':lon}
93 if elem.tag == "addressparts":
96 text = urllib2.unquote(addrpart.text)
102 elif tag == "country":
105 self.printable = printable_name(self.addr)