Skip to content

Geolocator

Geolocator #

Bases: Service

A control that allows you to fetch GPS data from your device.

This control is non-visual and should be added to Page.overlay list.

configuration #

configuration: GeolocatorConfiguration | None = None

Some additional configuration.

data #

data: Any = skip_field()

Arbitrary data of any type that can be attached to a control.

key #

key: (
    str | int | float | bool | ValueKey | ScrollKey | None
) = None

on_error #

on_error: ControlEventHandler[Geolocator] | None = None

Fires when an error occurs.

The data property of the event handler argument contains information on the error.

on_position_change #

on_position_change: (
    EventHandler[GeolocatorPositionChangeEvent] | None
) = None

Fires when the position of the device changes.

page #

page: Page | PageView | None

The page (of type Page or PageView) to which this control belongs to.

parent #

parent: BaseControl | None

The direct ancestor(parent) of this control.

It defaults to None and will only have a value when this control is mounted (added to the page tree).

The Page control (which is the root of the tree) is an exception - it always has parent=None.

position #

position: GeolocatorPosition | None = field(
    default=None, init=False
)

The current position of the device. (read-only)

Starts as None and will be updated when the position changes.

before_event #

before_event(e: ControlEvent)

before_update #

before_update()

before_update() method is called every time when the control is being updated. Make sure not to call update() method within before_update().

did_mount #

did_mount()

distance_between_async #

distance_between_async(
    start_latitude: Number,
    start_longitude: Number,
    end_latitude: Number,
    end_longitude: Number,
    timeout: float = 10,
)

Calculates the distance between the supplied coordinates in meters.

The distance between the coordinates is calculated using the Haversine formula (see https://en.wikipedia.org/wiki/Haversine_formula).

PARAMETER DESCRIPTION
start_latitude

The latitude of the starting point, in degrees.

TYPE: Number

start_longitude

The longitude of the starting point, in degrees.

TYPE: Number

end_latitude

The latitude of the ending point, in degrees.

TYPE: Number

end_longitude

The longitude of the ending point, in degrees.

TYPE: Number

timeout

The maximum amount of time (in seconds) to wait for a response.

TYPE: float DEFAULT: 10

RETURNS DESCRIPTION

The distance between the coordinates in meters.

RAISES DESCRIPTION
TimeoutError

If the request times out.

get_current_position_async #

get_current_position_async(
    configuration: GeolocatorConfiguration | None = None,
    timeout: float = 30,
) -> GeolocatorPosition

Gets the current position of the device with the desired accuracy and settings.

Note

Depending on the availability of different location services, this can take several seconds. It is recommended to call the [get_last_known_position][flet_geolocator.geolocator.Geolocator.get_last_known_position] method first to receive a known/cached position and update it with the result of the [get_current_position][flet_geolocator.geolocator.Geolocator.get_current_position] method.

PARAMETER DESCRIPTION
configuration

Additional configuration for the location request. If not specified, then the Geolocator.configuration property is used.

TYPE: GeolocatorConfiguration | None DEFAULT: None

timeout

The maximum amount of time (in seconds) to wait for a response.

TYPE: float DEFAULT: 30

RETURNS DESCRIPTION
GeolocatorPosition

The current position of the device as a GeolocatorPosition.

RAISES DESCRIPTION
TimeoutError

If the request times out.

get_last_known_position_async #

get_last_known_position_async(
    timeout: float = 10,
) -> GeolocatorPosition

Gets the last known position stored on the user's device. The accuracy can be defined using the Geolocator.configuration property.

Note

This method is not supported on web plaform.

PARAMETER DESCRIPTION
timeout

The maximum amount of time (in seconds) to wait for a response.

TYPE: float DEFAULT: 10

RETURNS DESCRIPTION
GeolocatorPosition

The last known position of the device as a GeolocatorPosition.

RAISES DESCRIPTION
AssertionError

If invoked on a web platform.

TimeoutError

If the request times out.

get_permission_status_async #

get_permission_status_async(
    timeout: float = 10,
) -> GeolocatorPermissionStatus

Gets which permission the app has been granted to access the device's location.

PARAMETER DESCRIPTION
timeout

The maximum amount of time (in seconds) to wait for a response.

TYPE: float DEFAULT: 10

RETURNS DESCRIPTION
GeolocatorPermissionStatus

The status of the permission.

RAISES DESCRIPTION
TimeoutError

If the request times out.

init #

init()

is_isolated #

is_isolated()

is_location_service_enabled_async #

is_location_service_enabled_async(
    timeout: float = 10,
) -> bool

Checks if location service is enabled.

PARAMETER DESCRIPTION
timeout

The maximum amount of time (in seconds) to wait for a response.

TYPE: float DEFAULT: 10

RETURNS DESCRIPTION
bool

True if location service is enabled, False otherwise.

RAISES DESCRIPTION
TimeoutError

If the request times out.

open_app_settings_async #

open_app_settings_async(timeout: float = 10) -> bool

Attempts to open the app's settings.

Note

This method is not supported on web plaform.

PARAMETER DESCRIPTION
timeout

The maximum amount of time (in seconds) to wait for a response.

TYPE: float DEFAULT: 10

RETURNS DESCRIPTION
bool

True if the app's settings were opened successfully, False otherwise.

RAISES DESCRIPTION
AssertionError

If invoked on a web platform.

TimeoutError

If the request times out.

open_location_settings #

open_location_settings(timeout: float = 10)

Attempts to open the device's location settings.

Note

This method is not supported on web plaform.

PARAMETER DESCRIPTION
timeout

The maximum amount of time (in seconds) to wait for a response.

TYPE: float DEFAULT: 10

RETURNS DESCRIPTION

True if the device's settings were opened successfully, False otherwise.

RAISES DESCRIPTION
AssertionError

If invoked on a web platform.

TimeoutError

If the request times out.

open_location_settings_async #

open_location_settings_async(timeout: float = 10)

Attempts to open the device's location settings.

Note

This method is not supported on web plaform.

PARAMETER DESCRIPTION
timeout

The maximum amount of time (in seconds) to wait for a response.

TYPE: float DEFAULT: 10

RETURNS DESCRIPTION

True if the device's settings were opened successfully, False otherwise.

RAISES DESCRIPTION
AssertionError

If invoked on a web platform.

TimeoutError

If the request times out.

request_permission_async #

request_permission_async(
    timeout: int = 60,
) -> GeolocatorPermissionStatus

Requests the device for access to the device's location.

PARAMETER DESCRIPTION
timeout

The maximum amount of time (in seconds) to wait for a response.

TYPE: int DEFAULT: 60

RETURNS DESCRIPTION
GeolocatorPermissionStatus

The status of the permission request.

RAISES DESCRIPTION
TimeoutError

If the request times out.

update #

update() -> None

will_unmount #

will_unmount()