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

js geolocation in adminui #77

Open
sayedmhm opened this issue Nov 1, 2023 · 0 comments
Open

js geolocation in adminui #77

sayedmhm opened this issue Nov 1, 2023 · 0 comments

Comments

@sayedmhm
Copy link

sayedmhm commented Nov 1, 2023

hi
How can I access the client's location
Whether through adminui or javascript
like this in nicegui

from nicegui import ui

async def show_location():
response = await ui.run_javascript('''
return await new Promise((resolve, reject) => {
if (!navigator.geolocation) {
reject(new Error('Geolocation is not supported by your browser'));
} else {
navigator.geolocation.getCurrentPosition(
(position) => {
resolve({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
});
},
() => {
reject(new Error('Unable to retrieve your location'));
}
);
}
});
''', timeout=5.0)
ui.notify(f'Your location is {response["latitude"]}, {response["longitude"]}')

ui.button('Show location', on_click=show_location)

ui.run()

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

1 participant