Share via


LocationManager.GetCurrentLocation Method

Definition

Overloads

GetCurrentLocation(String, LocationRequest, CancellationSignal, IExecutor, IConsumer)

Asynchronously returns a single current location fix from the given provider based on the given LocationRequest.

GetCurrentLocation(String, CancellationSignal, IExecutor, IConsumer)

Asynchronously returns a single current location fix from the given provider.

GetCurrentLocation(String, LocationRequest, CancellationSignal, IExecutor, IConsumer)

Asynchronously returns a single current location fix from the given provider based on the given LocationRequest.

[Android.Runtime.Register("getCurrentLocation", "(Ljava/lang/String;Landroid/location/LocationRequest;Landroid/os/CancellationSignal;Ljava/util/concurrent/Executor;Ljava/util/function/Consumer;)V", "GetGetCurrentLocation_Ljava_lang_String_Landroid_location_LocationRequest_Landroid_os_CancellationSignal_Ljava_util_concurrent_Executor_Ljava_util_function_Consumer_Handler", ApiSince=31)]
public virtual void GetCurrentLocation (string provider, Android.Locations.LocationRequest locationRequest, Android.OS.CancellationSignal? cancellationSignal, Java.Util.Concurrent.IExecutor executor, Java.Util.Functions.IConsumer consumer);
[<Android.Runtime.Register("getCurrentLocation", "(Ljava/lang/String;Landroid/location/LocationRequest;Landroid/os/CancellationSignal;Ljava/util/concurrent/Executor;Ljava/util/function/Consumer;)V", "GetGetCurrentLocation_Ljava_lang_String_Landroid_location_LocationRequest_Landroid_os_CancellationSignal_Ljava_util_concurrent_Executor_Ljava_util_function_Consumer_Handler", ApiSince=31)>]
abstract member GetCurrentLocation : string * Android.Locations.LocationRequest * Android.OS.CancellationSignal * Java.Util.Concurrent.IExecutor * Java.Util.Functions.IConsumer -> unit
override this.GetCurrentLocation : string * Android.Locations.LocationRequest * Android.OS.CancellationSignal * Java.Util.Concurrent.IExecutor * Java.Util.Functions.IConsumer -> unit

Parameters

provider
String

a provider listed by #getAllProviders()

locationRequest
LocationRequest

the location request containing location parameters

cancellationSignal
CancellationSignal

an optional signal that allows for cancelling this call

executor
IExecutor

the callback will take place on this Executor

consumer
IConsumer

the callback invoked with either a Location or null

Attributes

Remarks

Asynchronously returns a single current location fix from the given provider based on the given LocationRequest. This may activate sensors in order to compute a new location, unlike #getLastKnownLocation(String), which will only return a cached fix if available. 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.

The given location request may be used to provide hints on how a fresh location is computed if necessary. In particular LocationRequest#getDurationMillis() can be used to provide maximum duration allowed before failing. The system will always cap the maximum amount of time a request for current location may run to some reasonable value (less than a minute for example) before the request is failed.

Java documentation for android.location.LocationManager.getCurrentLocation(java.lang.String, android.location.LocationRequest, android.os.CancellationSignal, java.util.concurrent.Executor, java.util.function.Consumer<android.location.Location>).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

GetCurrentLocation(String, CancellationSignal, IExecutor, IConsumer)

Asynchronously returns a single current location fix from the given provider.

[Android.Runtime.Register("getCurrentLocation", "(Ljava/lang/String;Landroid/os/CancellationSignal;Ljava/util/concurrent/Executor;Ljava/util/function/Consumer;)V", "GetGetCurrentLocation_Ljava_lang_String_Landroid_os_CancellationSignal_Ljava_util_concurrent_Executor_Ljava_util_function_Consumer_Handler", ApiSince=30)]
public virtual void GetCurrentLocation (string provider, Android.OS.CancellationSignal? cancellationSignal, Java.Util.Concurrent.IExecutor executor, Java.Util.Functions.IConsumer consumer);
[<Android.Runtime.Register("getCurrentLocation", "(Ljava/lang/String;Landroid/os/CancellationSignal;Ljava/util/concurrent/Executor;Ljava/util/function/Consumer;)V", "GetGetCurrentLocation_Ljava_lang_String_Landroid_os_CancellationSignal_Ljava_util_concurrent_Executor_Ljava_util_function_Consumer_Handler", ApiSince=30)>]
abstract member GetCurrentLocation : string * Android.OS.CancellationSignal * Java.Util.Concurrent.IExecutor * Java.Util.Functions.IConsumer -> unit
override this.GetCurrentLocation : string * Android.OS.CancellationSignal * Java.Util.Concurrent.IExecutor * Java.Util.Functions.IConsumer -> unit

Parameters

provider
String

a provider listed by #getAllProviders()

cancellationSignal
CancellationSignal

an optional signal that allows for cancelling this call

executor
IExecutor

the callback will take place on this Executor

consumer
IConsumer

the callback invoked with either a Location or null

Attributes

Remarks

Asynchronously returns a single current location fix from the given provider.

See #getCurrentLocation(String, LocationRequest, CancellationSignal, Executor, Consumer) for more information.

Java documentation for android.location.LocationManager.getCurrentLocation(java.lang.String, android.os.CancellationSignal, java.util.concurrent.Executor, java.util.function.Consumer<android.location.Location>).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to