forked from x4nth055/pythoncode-tutorials
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse_geolocator.py
More file actions
Latest commit
25 lines (22 loc) · 777 Bytes
/
Copy pathreverse_geolocator.py
File metadata and controls
25 lines (22 loc) · 777 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
fromgeopy.geocodersimportNominatim
frompprintimportpprint
importtime
app=Nominatim(user_agent="tutorial")
defget_address_by_location(latitude, longitude, language="en"):
"""This function returns an address as raw from a location
will repeat until success"""
# build coordinates string to pass to reverse() function
coordinates=f"{latitude}, {longitude}"
# sleep for a second to respect Usage Policy
time.sleep(1)
try:
returnapp.reverse(coordinates, language=language).raw
except:
returnget_address_by_location(latitude, longitude)
# define your coordinates
latitude=36.723
longitude=3.188
# get the address info
address=get_address_by_location(latitude, longitude)
# print all returned data
pprint(address)