Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,10 @@ import folium
|
|
| 15 |
from streamlit_folium import st_folium
|
| 16 |
from vincenty import vincenty
|
| 17 |
import duckdb
|
|
|
|
|
|
|
| 18 |
|
|
|
|
| 19 |
st.set_page_config(layout="wide")
|
| 20 |
|
| 21 |
|
|
@@ -66,16 +69,22 @@ def distance(x):
|
|
| 66 |
|
| 67 |
def geocode(address):
|
| 68 |
try:
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
return lat, lon
|
| 80 |
|
| 81 |
|
|
|
|
| 15 |
from streamlit_folium import st_folium
|
| 16 |
from vincenty import vincenty
|
| 17 |
import duckdb
|
| 18 |
+
import os
|
| 19 |
+
import requests
|
| 20 |
|
| 21 |
+
geocode_key=os.environ["geocode_key"].
|
| 22 |
st.set_page_config(layout="wide")
|
| 23 |
|
| 24 |
|
|
|
|
| 69 |
|
| 70 |
def geocode(address):
|
| 71 |
try:
|
| 72 |
+
try:
|
| 73 |
+
address2 = address.replace(' ', '+').replace(',', '%2C')
|
| 74 |
+
df = pd.read_json(
|
| 75 |
+
f'https://geocoding.geo.census.gov/geocoder/locations/onelineaddress?address={address2}&benchmark=2020&format=json')
|
| 76 |
+
results = df.iloc[:1, 0][0][0]['coordinates']
|
| 77 |
+
lat, lon = results['y'], results['x']
|
| 78 |
+
except:
|
| 79 |
+
geolocator = Nominatim(user_agent="GTA Lookup")
|
| 80 |
+
geocode = RateLimiter(geolocator.geocode, min_delay_seconds=1)
|
| 81 |
+
location = geolocator.geocode(address)
|
| 82 |
+
lat, lon = location.latitude, location.longitude
|
| 83 |
+
except:
|
| 84 |
+
address = urllib.parse.quote(address)
|
| 85 |
+
url = 'https://api.geocod.io/v1.7/geocode?q=+'+address+f'&api_key={geocodio_new}'
|
| 86 |
+
json_reponse=requests.get(url,verify=False).json()
|
| 87 |
+
lat,lon = json_reponse['results'][0]['location'].values()
|
| 88 |
return lat, lon
|
| 89 |
|
| 90 |
|