Geolocator
Geolocator fetches Position from device GPS. Works on macOS, Windows, iOS, Android and web. Based on the geolocator Dart/Flutter package.
Geolocator control is non-visual and should be added to page.overlay
list.
To build your Flet app that uses Geolocator
control add --include-packages flet_geolocator
to flet build
command, for example:
flet build apk --include-packages flet_geolocator
Examples
Basic Example
loading...
Properties
location_settings
Value is of type GeolocatorSettings
.
Methods
get_current_position(accuracy, location_settings)
Gets the current position of the device with the desired accuracy and settings.
This method has the following properties:
accuracy
: value is of typeGeolocatorPositionAccuracy
and defaults toGeolocatorPositionAccuracy.BEST
.location_settings
: value is of typeGeolocatorSettings
. If not specified, then thelocation_settings
property is used.
Returns an instance of type GeolocatorPosition
.
Note: Depending on the availability of different location services, this can take several seconds.
It is recommended to call the get_last_known_position()
method first to receive a known/cached position and update it
with the result of get_current_position()
get_last_known_position()
Gets the last known position of the device with the specified accuracy. The accuracy can be defined using the location_settings
property.
Returns an instance of type GeolocatorPosition
.
get_permission_status()
Gets which permission the app has been granted to access the device's location.
Returns an instance of type GeolocatorPermissionStatus
.
request_permission()
Requests the device for access to the device's location.
Returns an instance of type GeolocatorPermissionStatus
.
is_location_service_enabled()
Checks if location service is enable.
Returns a boolean value: True
if location service is enabled, False
otherwise.
open_app_settings()
Attempts to open device's app settings.
Returns a boolean value: True
if the device's settings were opened successfully, False
otherwise.
open_location_settings()
Attempts to open device's location settings.
Returns a boolean value: True
if the device's settings were opened successfully, False
otherwise.
Events
on_error
Fires when an error occurs.
on_position_change
Fires when the position of the device changes.
Event handler argument is of type GeolocatorPositionChangeEvent
.