building_selection_tool/helpers.py

24 lines
580 B
Python

"""
Helpers
"""
import requests
#OpenCage Geocoding API key
API_KEY = '744ad0d2d58e49d1ac57d6fb04fe5d82'
def get_gps_coordinate_by_address(address):
base_url = "https://api.opencagedata.com/geocode/v1/json"
params = {
'q': address,
'key': API_KEY,
}
response = requests.get(base_url, params=params)
data = response.json()
if response.status_code == 200 and data['status']['code'] == 200:
location = data['results'][0]['geometry']
return location['lat'], location['lng']
else:
print(f"Error: {data['status']['message']}")
return None, None