rodrigosantosbr

[Py] Latitude Longitude with geopy

Aug 2nd, 2019 (edited)
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. # pip install geopy
  2. from geopy.geocoders import Yandex
  3. import json
  4. geolocator = Yandex(lang='pt_BR')
  5. city = "sobral"
  6. country = "BR"
  7. location = geolocator.geocode(str(city + ',' + country))
  8. if location != None:
  9.     # print(json.dumps(location.raw, indent=4))
  10.     print(location.address)
  11.     print("latitude: {}".format(location.latitude))
  12.     print("longitude: {}".format(location.longitude))
  13. else:
  14.     print(location)
  15.  
  16. location = geolocator.geocode("Rio Branco, Acre, Brasil")
  17. print("latitude: {}".format(location.latitude))
  18. print("longitude: {}".format(location.longitude))
  19.  
  20. location = geolocator.reverse("-9.969687, -67.825427", exactly_one=True)
  21. print(location.address)
Add Comment
Please, Sign In to add comment