Skip to content

accessing GPS #257

Closed Answered by falkoschindler
keepexploring asked this question in Q&A
Discussion options

You must be logged in to vote

Sure, you could certainly create a custom component for getting the geolocation.

But if you basically just want to call a JavaScript function, you can also use ui.run_javasscript:

async def get_location():
    result = await ui.run_javascript('''
        return await new Promise((resolve, reject) => {
            if ("geolocation" in navigator) {
                navigator.geolocation.getCurrentPosition(
                    position => resolve({
                        lat: position.coords.latitude,
                        lon: position.coords.longitude,
                    }),
                    error => reject(error),
                );
            } else {
                reject("Geolo…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by keepexploring
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #256 on January 18, 2023 16:39.