LinhVuu/Banking-Advanced-Authentication-System
0
1import streamlit as st2from bokeh.models.widgets import Button3from bokeh.models import CustomJS4from streamlit_bokeh_events import streamlit_bokeh_events5from geopy.geocoders import Nominatim6 7loc_button = Button(label="Get Location")8loc_button.js_on_event("button_click", CustomJS(code="""9 navigator.geolocation.getCurrentPosition(10 (loc) => {11 document.dispatchEvent(new CustomEvent("GET_LOCATION", {detail: {lat: loc.coords.latitude, lon: loc.coords.longitude}}))12 }13 )14 """))15result = streamlit_bokeh_events(16 loc_button,17 events="GET_LOCATION",18 key="get_location",19 refresh_on_update=False,20 override_height=75,21 debounce_time=0)22 23if result:24 if "GET_LOCATION" in result:25 st.write(result.get("GET_LOCATION"))26 # print(result.get("GET_LOCATION")["lat"]) 27 lat = str(result.get("GET_LOCATION")["lat"])28 lon = str(result.get("GET_LOCATION")["lon"])29 30 # Get address from given coordinate31 geolocator = Nominatim(user_agent="BAAM")32 location = geolocator.reverse(lat + "," + lon)33 address = location.raw['address']34 st.write(str(location))35 st.write(address)36 print(address)37 print(type(str(location)))