Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to know when user has denied location with get_geolocation()? #13

Open
emigre459 opened this issue Jan 2, 2025 · 2 comments
Open

Comments

@emigre459
Copy link

I'm trying to disable a button I've created for grabbing the user location when the user denies location services in their browser dialog after a call to get_geolocation(). How do I detect that that denial has occurred so I can disable the button going forward? I've tried using the below code but it always returns None for both the session state variable and the returned value from streamlit_js_eval (I've also tried making it a raw string in python to avoid concerns with things like the {} brackets but no luck). This throws no errors:

allowed = st_js(js_expressions="navigator.permissions.query({name:'geolocation'})", key="geolocation_permission")
st.write(f"Geolocation permitted: {allowed} and {ss.geolocation_permission}")
@aghasemi
Copy link
Owner

aghasemi commented Jan 2, 2025

Hi. Have you tried checking if the result of get_geolocation is None?

@emigre459
Copy link
Author

So far as I can tell, that function executes asynchronously. So right now I have to wait some timeout period, checking if the value has changed from None to something else, even if the user has permitted location services. Unfortunately this means that I can't tell if a value of None means "user will not permit" or "timeout reached" (I use 10 seconds and that is sometimes not enough even when permission is granted - why does it seem so slow btw?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants