JourneyJoker/auction/helpers.py
Klaus-Uwe Mitterer 6d67541571 Demo notifications
Fixed a few views
Other stuff
2021-04-08 11:30:19 +02:00

16 lines
No EOL
511 B
Python

from dbsettings.functions import getValue
import requests
def name_to_coords(name, api_key=None):
URL = "https://maps.googleapis.com/maps/api/geocode/json"
api_key = api_key or getValue("google.api.key")
payload = {"address": name, "key": api_key}
response = requests.get(URL, params=payload).json()
try:
result = response["results"][0]
return result["geometry"]["location"]["lat"], result["geometry"]["location"]["lng"]
except:
raise ValueError(response)