Geolocator

Access device location services in your Flet app using the flet-geolocator extension. This control wraps Flutter's geolocator package.

Platform Support

  • **Windows**: ✅
  • **macOS**: ✅
  • **Linux**: ✅
  • **iOS**: ✅
  • **Android**: ✅
  • **Web**: ✅
  • 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 | None
  • - Type: class-attribute, instance-attribute - Description: Additional configuration for the geolocator.
  • **position**: flet_geolocator.types.GeolocatorPosition | None
  • - Type: class-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 | None
  • - Type: class-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]] | None
  • - Type: class-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)** -> Number
  • - Type: async - 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)** -> GeolocatorPosition
  • - Type: async - 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()** -> GeolocatorPosition
  • - Type: async - 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()** -> GeolocatorPermissionStatus
  • - Type: async - Description: Gets the current location permission status for the app. - Returns: The permission status.

  • **is_location_service_enabled()** -> bool
  • - Type: async - Description: Checks if the device's location service is enabled. - Returns: True if enabled, False otherwise.

  • **open_app_settings()** -> bool
  • - Type: async - 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()** -> bool
  • - Type: async - 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()** -> GeolocatorPermissionStatus
  • - Type: async - Description: Requests the device for location access permission. - Returns: The status of the permission request.