Advertisement
Guest User

Untitled

a guest
Aug 9th, 2023
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. import requests
  2.  
  3. def get_city_from_coordinates(latitude, longitude, api_key):
  4.     base_url = "https://maps.googleapis.com/maps/api/geocode/json?latlng={},{}&key={}"
  5.     response = requests.get(base_url.format(latitude, longitude, api_key))
  6.     data = response.json()
  7.  
  8.     for result in data['results']:
  9.         for component in result['address_components']:
  10.             if 'locality' in component['types']:
  11.                 return component['long_name']
  12.  
  13.     return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement