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.
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
#
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_update
#
before_update()
method is called every time when the control is being updated.
Make sure not to call update()
method within before_update()
.
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:
|
start_longitude
|
The longitude of the starting point, in degrees.
TYPE:
|
end_latitude
|
The latitude of the ending point, in degrees.
TYPE:
|
end_longitude
|
The longitude of the ending point, in degrees.
TYPE:
|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
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
TYPE:
|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
GeolocatorPosition
|
The current position of the device as a |
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:
|
RETURNS | DESCRIPTION |
---|---|
GeolocatorPosition
|
The last known position of the device as a |
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:
|
RETURNS | DESCRIPTION |
---|---|
GeolocatorPermissionStatus
|
The status of the permission. |
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
is_location_service_enabled_async
#
Checks if location service is enabled.
PARAMETER | DESCRIPTION |
---|---|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
|
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
open_app_settings_async
#
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:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
|
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:
|
RETURNS | DESCRIPTION |
---|---|
|
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:
|
RETURNS | DESCRIPTION |
---|---|
|
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:
|
RETURNS | DESCRIPTION |
---|---|
GeolocatorPermissionStatus
|
The status of the permission request. |
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |