Geolocator
Access device location services in your Flet app using the flet-geolocator extension. This control wraps Flutter's geolocator package.
Platform Support
Installation
1. Add flet-geolocator to your project dependencies:
uv add flet-geolocator
# or
pip install flet-geolocator
2. Manually add the package to requirements.txt or pyproject.toml.**Important**: Request permissions using request_permission or get_permission_status before accessing location data.
Description
Inherits from flet.Service.
Properties
configuration**: flet_geolocator.types.GeolocatorConfiguration | Noneclass-attribute, instance-attribute
- Description: Additional configuration for the geolocator.
position**: flet_geolocator.types.GeolocatorPosition | Noneclass-attribute, instance-attribute
- Description: The current position of the device (read-only). Starts as None and updates when position changes.Events
on_error**: flet.ControlEventHandler | Noneclass-attribute, instance-attribute
- Description: Fires when an error occurs. The data property of the event argument contains error information.
on_position_change**: flet.EventHandler[[GeolocatorPositionChangeEvent]] | Noneclass-attribute, instance-attribute
- Description: Fires when the device's position changes.Methods
distance_between(start_latitude: Number, start_longitude: Number, end_latitude: Number, end_longitude: Number)** -> Numberasync
- Description: Calculates the distance between two sets of coordinates in meters using the Haversine formula.
- Parameters:
- start_latitude: Latitude of the starting point (degrees).
- start_longitude: Longitude of the starting point (degrees).
- end_latitude: Latitude of the ending point (degrees).
- end_longitude: Longitude of the ending point (degrees).
- Returns: The distance in meters.get_current_position(configuration: GeolocatorConfiguration | None = None)** -> GeolocatorPositionasync
- Description: Gets the current position of the device with specified accuracy and settings. Can take several seconds. Recommended to call get_last_known_position first.
- Parameters:
- configuration: Optional GeolocatorConfiguration. Uses Geolocator.configuration if not provided.
- Returns: The current device position.get_last_known_position()** -> GeolocatorPositionasync
- Description: Gets the last known position stored on the device. Accuracy can be configured via Geolocator.configuration. Not supported on web.
- Returns: The last known device position.
- Raises: FletUnsupportedPlatformException on web.get_permission_status()** -> GeolocatorPermissionStatusasync
- Description: Gets the current location permission status for the app.
- Returns: The permission status.is_location_service_enabled()** -> boolasync
- Description: Checks if the device's location service is enabled.
- Returns: True if enabled, False otherwise.open_app_settings()** -> boolasync
- Description: Attempts to open the app's settings. Not supported on web.
- Returns: True if successful, False otherwise.
- Raises: FletUnsupportedPlatformException on web.open_location_settings()** -> boolasync
- Description: Attempts to open the device's location settings. Not supported on web.
- Returns: True if successful, False otherwise.
- Raises: FletUnsupportedPlatformException on web.request_permission()** -> GeolocatorPermissionStatusasync
- Description: Requests the device for location access permission.
- Returns: The status of the permission request.