-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeolocation.py
49 lines (37 loc) · 1.15 KB
/
geolocation.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import geopy
from geopy.geocoders import Nominatim
class Geolocation:
def __init__(self, agent):
self.geolocator = Nominatim(user_agent=agent)
def get_address(self, location):
geolocation = self.geolocator.reverse(location)
try:
road = geolocation.raw['address']['road']
except:
road = ""
try:
house = " " + geolocation.raw['address']['house_number']
except:
house = ""
try:
city = ", " + geolocation.raw['address']['city']
except:
city = ""
try:
town = ", " + geolocation.raw['address']['town']
except:
town = ""
try:
village = ", " + geolocation.raw['address']['village']
except:
village = ""
try:
country = ", " + geolocation.raw['address']['country']
except:
country = ""
try:
postcode = ", " + geolocation.raw['address']['postcode']
except:
postcode = ""
address = road + house + postcode + village + town + city + country
return address