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: Optional[GeolocatorConfiguration] = None
#
Some additional configuration.
on_error: ft.OptionalControlEventCallable = None
#
Fires when an error occurs.
The data
property of the event handler argument contains information on the error.
on_position_change: ft.OptionalEventCallable[GeolocatorPositionChangeEvent] = None
#
Fires when the position of the device changes.
Event handler argument is of type GeolocatorPositionChangeEvent
.
position: Optional[GeolocatorPosition] = None
#
The current position of the device.
Starts as None
and will be updated when the position changes.
distance_between_async(start_latitude: ft.Number, start_longitude: ft.Number, end_latitude: ft.Number, end_longitude: ft.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:
|
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
RETURNS | DESCRIPTION |
---|---|
The distance between the coordinates in meters. |
get_current_position_async(configuration: Optional[GeolocatorConfiguration] = None, timeout: float = 30) -> GeolocatorPosition
#
Gets the current position of the device with the desired accuracy and settings.
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:
|
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
RETURNS | DESCRIPTION |
---|---|
GeolocatorPosition
|
The current position of the device as a |
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.
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.
Not supported on web plaform.
PARAMETER | DESCRIPTION |
---|---|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
AssertionError
|
If called on a web page, as this method is not supported on web. |
TimeoutError
|
If the request times out. |
RETURNS | DESCRIPTION |
---|---|
GeolocatorPosition
|
|
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:
|
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
RETURNS | DESCRIPTION |
---|---|
GeolocatorPermissionStatus
|
The status of the permission. |
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:
|
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
RETURNS | DESCRIPTION |
---|---|
bool
|
|
open_app_settings_async(timeout: float = 10) -> bool
#
Attempts to open the app's settings.
Not supported on web plaform.
PARAMETER | DESCRIPTION |
---|---|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
AssertionError
|
If called on a web page, as this method is not supported on web. |
TimeoutError
|
If the request times out. |
RETURNS | DESCRIPTION |
---|---|
bool
|
|
open_location_settings(timeout: float = 10)
#
Attempts to open the device's location settings.
Not supported on web plaform.
PARAMETER | DESCRIPTION |
---|---|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
AssertionError
|
If called on a web page, as this method is not supported on web. |
TimeoutError
|
If the request times out. |
RETURNS | DESCRIPTION |
---|---|
|
open_location_settings_async(timeout: float = 10)
#
Attempts to open the device's location settings.
Not supported on web plaform.
PARAMETER | DESCRIPTION |
---|---|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
AssertionError
|
If called on a web page, as this method is not supported on web. |
TimeoutError
|
If the request times out. |
RETURNS | DESCRIPTION |
---|---|
|
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:
|
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
RETURNS | DESCRIPTION |
---|---|
GeolocatorPermissionStatus
|
The status of the permission request. |