Skip to content

js geolocation in adminui #77

Description

@sayedmhm

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()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions