ybendou commited on
Commit
4b4bdda
·
1 Parent(s): 61a6aaf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -27
app.py CHANGED
@@ -205,33 +205,25 @@ interventions_df = parse_gg_sheet(INTERVENTIONS_URL)
205
  interventions_df = add_latlng_col(interventions_df, process_column=12)
206
 
207
  # Get current location:
208
-
209
- # Add unique id to the input element
210
- st.markdown('<input id="localisation" type="text" style="display:none;">', unsafe_allow_html=True)
211
-
212
- js_code = """
213
- function getLocation() {
214
- navigator.geolocation.getCurrentPosition(function (position) {
215
- document.getElementById("localisation").value = JSON.stringify({
216
- latitude: position.coords.latitude,
217
- longitude: position.coords.longitude
218
- });
219
- document.getElementById("localisation").dispatchEvent(new Event('input', { 'bubbles': true }));
220
- }, function () {
221
- document.getElementById("localisation").value = JSON.stringify({
222
- latitude: null,
223
- longitude: null
224
- });
225
- document.getElementById("localisation").dispatchEvent(new Event('input', { 'bubbles': true }));
226
- });
227
- }
228
- getLocation();
229
- console.log(localisation);
230
- """
231
- st.markdown(f"<script>{js_code}</script>", unsafe_allow_html=True)
232
-
233
- # Hidden field to store the JavaScript variable
234
- current_localisation = st.text_input("localisation", "", key="localisation", label_visibility="hidden")
235
 
236
  m = init_map(current_localisation=current_localisation)
237
 
 
205
  interventions_df = add_latlng_col(interventions_df, process_column=12)
206
 
207
  # Get current location:
208
+ from bokeh.models.widgets import Button
209
+ from bokeh.models import CustomJS
210
+ from streamlit_bokeh_events import streamlit_bokeh_events
211
+
212
+ loc_button = Button(label="Get Location")
213
+ loc_button.js_on_event("button_click", CustomJS(code="""
214
+ navigator.geolocation.getCurrentPosition(
215
+ (loc) => {
216
+ document.dispatchEvent(new CustomEvent("GET_LOCATION", {detail: {lat: loc.coords.latitude, lon: loc.coords.longitude}}))
217
+ }
218
+ )
219
+ """))
220
+ current_localisation = streamlit_bokeh_events(
221
+ loc_button,
222
+ events="GET_LOCATION",
223
+ key="get_location",
224
+ refresh_on_update=False,
225
+ override_height=75,
226
+ debounce_time=0)
 
 
 
 
 
 
 
 
227
 
228
  m = init_map(current_localisation=current_localisation)
229