Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- def get_city_from_coordinates(latitude, longitude, api_key):
- base_url = "https://maps.googleapis.com/maps/api/geocode/json?latlng={},{}&key={}"
- response = requests.get(base_url.format(latitude, longitude, api_key))
- data = response.json()
- for result in data['results']:
- for component in result['address_components']:
- if 'locality' in component['types']:
- return component['long_name']
- return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement