🔍Geolocator
The compass-geolocator
artifact provides an interface Geolocator
that has members for:
Getting the current location
Starting and stopping tracking the location
Check if location services are available
Creating a Geolocator
To get an instance of Geolocator
you can use the factory function:
Locator
A Locator
is interface that can be implemented to provide all of the geolocation functionality.
Compass provides Locator
's for Android / iOS and the Browser:
There are also included extension functions for each artifact:
There are similar extension functions for the Browserartifact.
Make sure you add the proper dependencies, see All Dependencies.
Custom Locator
If you would like to provide your own you can implement the object yourself:
Permissions
Compass will handle the permissions for Android and iOS automatically for you, see Android / iOS.
Current location
To get the current location of the device call Geolocator.current()
. It will return a GeolocatorResult
, or you can use one of the extension functions:
GeolocatorResult
When you call Geolocator.current()
you will receive a GeolocationResult.
It can be one of the following:
GeolocatorResult.Success
This has contains a
Location
object of the current location details.
GeolocatorResult.Error
NotSupported
: Geolocation is not supported on this deviceGeolocationFailed
: Geolocation failed for an unknown reasonPermissionError
: We don't have permission to use the geolocation services
Tracking location
You can subscribe to location updates by collecting the Geolocator.locationUpdates
, or to get updates to the status of tracking (errors, permissions, updates) use Geolocator.trackingStatus
:
Location details
You can read about what kind of data is in the Location
object by reading Location.
Last updated