Location Service
Service to obtain device location.
Types
Google Play Services status.
Listener to notify current location. When current location is requested using getCurrentLocation, method returns immediately and listener might be called later if no cached location is readily available, in such cases system must wait until a new location update is received.
Listener to notify periodic location updates.
Properties
Indicates whether Google Play Services is available. More detailed information can be obtained at googlePlayServicesStatus.
Gets status for Google Play Services.
Indicates whether location is enabled on current device. True indicates that location is enabled, false indicates that location is disabled, null indicates that status is unknown. Notice that location status is only available for SDK 28 or later.
Listener to be notified of location updates.
Minimum distance between location updates in meters. By default this is zero meters. By modifying this value, the frequency to request location updates changes, and consequently so does battery usage. A reasonable value must be used for each use case. Changing this value while updates are already being requested has no effect until location updates are cancelled by calling cancelLocationUpdates and new updates are requested again.
Minimum time interval between location updates in milliseconds. By default this is one second. By modifying this value, the frequency to request location updates changes, and consequently so does battery usage. A reasonable value must be used for each use case. Changing this value while updates are already being requested has no effect until location updates are cancelled by calling cancelLocationUpdates and new updates are requested again.
Functions
Cancels current location request if there is an ongoing request, otherwise makes no action.
Cancels periodic location updates. This should be called whenever periodic location updates are no longer needed to preserve battery life.
Requests a single location update. Returns a cached last known location if it was recently cached or waits until a new location is received if none is already available. Because this method might use cached locations, returned value in callback may not be the most recent one. This method returns immediately and notifies in provided listener when location is found. Current location request can be cancelled by calling cancelCurrentLocation. Once the request is cancelled, provider listener is no longer called. There are no guarantees on which thread the listener will be called on. This will depend on Android version on the device and whether Google Play Services location provider is available or not.
Gets last known location. This method attempts to retrieve last cached device location, if available. If no previous location is known, null is returned. This method does not attempt to retrieve a new location if no location is known. Location permission is required
Requests continuous location updates for current updateInterval and smallestDisplacement. By modifying both updateInterval and smallestDisplacement, the frequency to request location updates changes, and consequently so does battery usage. Reasonable values must be used for each use case. Current locationUpdateListener will be notified until cancelLocationUpdates is called.