Skip to main content

Geolocator control for Flet

Project description

Geolocator control for Flet

Geolocator control for Flet.

Usage

Add flet-geolocator as dependency (pyproject.toml or requirements.txt) to your Flet project.

Example

import flet as ft

import flet_geolocator as fg


async def main(page: ft.Page):
    page.scroll = ft.ScrollMode.ADAPTIVE
    page.appbar = ft.AppBar(title=ft.Text("Geolocator Tests"))

    def handle_position_change(e):
        page.add(ft.Text(f"New position: {e.latitude} {e.longitude}"))

    gl = fg.Geolocator(
        location_settings=fg.GeolocatorSettings(
            accuracy=fg.GeolocatorPositionAccuracy.LOW
        ),
        on_position_change=handle_position_change,
        on_error=lambda e: page.add(ft.Text(f"Error: {e.data}")),
    )
    page.overlay.append(gl)

    settings_dlg = lambda handler: ft.AlertDialog(
        adaptive=True,
        title=ft.Text("Opening Location Settings..."),
        content=ft.Text(
            "You are about to be redirected to the location/app settings. "
            "Please locate this app and grant it location permissions."
        ),
        actions=[ft.TextButton(text="Take me there", on_click=handler)],
        actions_alignment=ft.MainAxisAlignment.CENTER,
    )

    async def handle_permission_request(e):
        p = await gl.request_permission_async(wait_timeout=60)
        page.add(ft.Text(f"request_permission: {p}"))

    async def handle_get_permission_status(e):
        p = await gl.get_permission_status_async()
        page.add(ft.Text(f"get_permission_status: {p}"))

    async def handle_get_current_position(e):
        p = await gl.get_current_position_async()
        page.add(ft.Text(f"get_current_position: ({p.latitude}, {p.longitude})"))

    async def handle_get_last_known_position(e):
        p = await gl.get_last_known_position_async()
        page.add(ft.Text(f"get_last_known_position: ({p.latitude}, {p.longitude})"))

    async def handle_location_service_enabled(e):
        p = await gl.is_location_service_enabled_async()
        page.add(ft.Text(f"is_location_service_enabled: {p}"))

    async def handle_open_location_settings(e):
        p = await gl.open_location_settings_async()
        page.close(location_settings_dlg)
        page.add(ft.Text(f"open_location_settings: {p}"))

    async def handle_open_app_settings(e):
        p = await gl.open_app_settings_async()
        page.close(app_settings_dlg)
        page.add(ft.Text(f"open_app_settings: {p}"))

    location_settings_dlg = settings_dlg(handle_open_location_settings)
    app_settings_dlg = settings_dlg(handle_open_app_settings)

    page.add(
        ft.Row(
            wrap=True,
            controls=[
                ft.OutlinedButton(
                    "Request Permission",
                    on_click=handle_permission_request,
                ),
                ft.OutlinedButton(
                    "Get Permission Status",
                    on_click=handle_get_permission_status,
                ),
                ft.OutlinedButton(
                    "Get Current Position",
                    on_click=handle_get_current_position,
                ),
                ft.OutlinedButton(
                    "Get Last Known Position",
                    visible=False if page.web else True,
                    on_click=handle_get_last_known_position,
                ),
                ft.OutlinedButton(
                    "Is Location Service Enabled",
                    on_click=handle_location_service_enabled,
                ),
                ft.OutlinedButton(
                    "Open Location Settings",
                    visible=False if page.web else True,
                    on_click=lambda e: page.open(location_settings_dlg),
                ),
                ft.OutlinedButton(
                    "Open App Settings",
                    visible=False if page.web else True,
                    on_click=lambda e: page.open(app_settings_dlg),
                ),
            ],
        )
    )


ft.app(main)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flet_geolocator-0.1.0.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

flet_geolocator-0.1.0-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file flet_geolocator-0.1.0.tar.gz.

File metadata

  • Download URL: flet_geolocator-0.1.0.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.18

File hashes

Hashes for flet_geolocator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c7f42ff936468e5f33e9edd127ec94da710449108b6f9f830990816a66a8d91b
MD5 fe4f00cd82395e8ba5035c43a2473ca4
BLAKE2b-256 29bce38751ba03c79c42d4bfb72e33898399004f620f9599cb30bc9d904c8ac8

See more details on using hashes here.

File details

Details for the file flet_geolocator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flet_geolocator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4878d7f6d5dfc1e4e55011f2ccb90ea2e11c6b58bb3d2389a0406f37f28bb125
MD5 a0d849430ee86dddfbe7c2dc765e7f89
BLAKE2b-256 83f2b7851c95a13b0fe3809061d31501ab911191f2ad33730b8a0d2dee0a6b55

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page