|
import streamlit as st |
|
from bokeh.models.widgets import Button |
|
from bokeh.models import CustomJS |
|
from streamlit_bokeh_events import streamlit_bokeh_events |
|
from geopy.geocoders import Nominatim |
|
|
|
loc_button = Button(label="Get Location") |
|
loc_button.js_on_event("button_click", CustomJS(code=""" |
|
navigator.geolocation.getCurrentPosition( |
|
(loc) => { |
|
document.dispatchEvent(new CustomEvent("GET_LOCATION", {detail: {lat: loc.coords.latitude, lon: loc.coords.longitude}})) |
|
} |
|
) |
|
""")) |
|
result = streamlit_bokeh_events( |
|
loc_button, |
|
events="GET_LOCATION", |
|
key="get_location", |
|
refresh_on_update=False, |
|
override_height=75, |
|
debounce_time=0) |
|
|
|
if result: |
|
if "GET_LOCATION" in result: |
|
st.write(result.get("GET_LOCATION")) |
|
|
|
lat = str(result.get("GET_LOCATION")["lat"]) |
|
lon = str(result.get("GET_LOCATION")["lon"]) |
|
|
|
|
|
geolocator = Nominatim(user_agent="BAAM") |
|
location = geolocator.reverse(lat + "," + lon) |
|
address = location.raw['address'] |
|
st.write(str(location)) |
|
st.write(address) |
|
print(address) |
|
print(type(str(location))) |