getCurrentLocation

@RequiresPermission(anyOf = [])
open fun getCurrentLocation(@NonNull locationManager: @NonNull LocationManager, @NonNull provider: @NonNull String, @Nullable cancellationSignal: @Nullable CancellationSignal, @NonNull executor: @NonNull Executor, @NonNull consumer: @NonNull Consumer<Location>)(source)

Asynchronously returns a single current location fix from the given provider. This may activate sensors in order to compute a new location. The given callback will be invoked once and only once, either with a valid location or with a null location if the provider was unable to generate a valid location.

A client may supply an optional CancellationSignal. If this is used to cancel the operation, no callback should be expected after the cancellation.

This method may return locations from the very recent past (on the order of several seconds), but will never return older locations (for example, several minutes old or older). Clients may rely upon the guarantee that if this method returns a location, it will represent the best estimation of the location of the device in the present moment.

Clients calling this method from the background may notice that the method fails to determine a valid location fix more often than while in the foreground. Background applications may be throttled in their location accesses to some degree.


@RequiresPermission(anyOf = [])
open fun getCurrentLocation(@NonNull locationManager: @NonNull LocationManager, @NonNull provider: @NonNull String, cancellationSignal: @Nullable CancellationSignal, @NonNull executor: @NonNull Executor, @NonNull consumer: @NonNull Consumer<Location>)(source)

Deprecated

Use getCurrentLocation

Asynchronously returns a single current location fix from the given provider. This may activate sensors in order to compute a new location. The given callback will be invoked once and only once, either with a valid location or with a null location if the provider was unable to generate a valid location.

A client may supply an optional CancellationSignal. If this is used to cancel the operation, no callback should be expected after the cancellation.

This method may return locations from the very recent past (on the order of several seconds), but will never return older locations (for example, several minutes old or older). Clients may rely upon the guarantee that if this method returns a location, it will represent the best estimation of the location of the device in the present moment.

Clients calling this method from the background may notice that the method fails to determine a valid location fix more often than while in the foreground. Background applications may be throttled in their location accesses to some degree.