Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -50,7 +50,7 @@ def get_zip_codes(city, state):
|
|
50 |
else:
|
51 |
return []
|
52 |
|
53 |
-
def get_coordinates(
|
54 |
"""
|
55 |
Get the coordinates (latitude and longitude) of an address using the OpenWeather Geocoding API.
|
56 |
|
@@ -61,7 +61,16 @@ def get_coordinates(address: str, api_key: str) -> list:
|
|
61 |
Returns:
|
62 |
list: A list containing the latitude and longitude of the address.
|
63 |
"""
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
def haversine(lat1, lon1, lat2, lon2):
|
67 |
R = 6371 # Earth radius in kilometers. Use 3956 for miles.
|
|
|
50 |
else:
|
51 |
return []
|
52 |
|
53 |
+
def get_coordinates(zipcode: str, api_key: str) -> list:
|
54 |
"""
|
55 |
Get the coordinates (latitude and longitude) of an address using the OpenWeather Geocoding API.
|
56 |
|
|
|
61 |
Returns:
|
62 |
list: A list containing the latitude and longitude of the address.
|
63 |
"""
|
64 |
+
|
65 |
+
base_url = "http://api.openweathermap.org/geo/1.0/zip"
|
66 |
+
params = {
|
67 |
+
'zip': zipcode + ",US",
|
68 |
+
'appid': api_key
|
69 |
+
}
|
70 |
+
|
71 |
+
response = requests.get(base_url, params=params)
|
72 |
+
data = response.json()
|
73 |
+
return [data.get('lat'), data.get('lon')]
|
74 |
|
75 |
def haversine(lat1, lon1, lat2, lon2):
|
76 |
R = 6371 # Earth radius in kilometers. Use 3956 for miles.
|