共用方式為


LocationManager.GetCurrentLocation 方法

定義

多載

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

根據指定的 LocationRequest,以異步方式從指定的提供者傳回單一目前位置修正。

GetCurrentLocation(String, CancellationSignal, IExecutor, IConsumer)

以異步方式從指定的提供者傳回單一目前位置修正。

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

根據指定的 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

參數

provider
String

列出的提供者 #getAllProviders()

locationRequest
LocationRequest

包含位置參數的位置要求

cancellationSignal
CancellationSignal

允許取消此呼叫的選擇性訊號

executor
IExecutor

回呼將會在此進行 Executor

consumer
IConsumer

使用 或 null 叫用 Location 的回呼

屬性

備註

根據指定的 LocationRequest,以異步方式從指定的提供者傳回單一目前位置修正。 這可能會啟動感測器來計算新的位置,不像 #getLastKnownLocation(String),只有在可用時,才會傳回快取的修正程式。 如果提供者無法產生有效的位置,則會叫用指定的回呼一次,且只會叫用一次,或是具有 Null 位置。

用戶端可能會提供選擇性 CancellationSignal的 。 如果這是用來取消作業,則取消之後不應預期回呼。

這個方法可能會從最近的過去傳回位置(依秒數的順序),但永遠不會傳回較舊的位置(例如,舊幾分鐘或較舊)。 用戶端可能會依賴保證,如果此方法傳回位置,它將會代表目前裝置位置的最佳估計。

從背景呼叫這個方法的用戶端可能會注意到方法無法判斷有效的位置修正頻率會比前景更頻繁。 背景應用程式可能會對其位置存取進行一定程度的節流。

指定的位置要求可用來提供在必要時如何計算新位置的提示。 特別是 LocationRequest#getDurationMillis() 可用來提供失敗前允許的最大持續時間。 系統一律會將要求目前位置的要求時間上限上限為一些合理的值(例如,小於一分鐘),然後要求失敗。

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

此頁面的部分是根據 Android 開放原始碼專案所建立和共用的工作進行修改,並根據 Creative Commons 2.5 屬性授權中所述的詞彙使用。

適用於

GetCurrentLocation(String, CancellationSignal, IExecutor, IConsumer)

以異步方式從指定的提供者傳回單一目前位置修正。

[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

參數

provider
String

列出的提供者 #getAllProviders()

cancellationSignal
CancellationSignal

允許取消此呼叫的選擇性訊號

executor
IExecutor

回呼將會在此進行 Executor

consumer
IConsumer

使用 或 null 叫用 Location 的回呼

屬性

備註

以異步方式從指定的提供者傳回單一目前位置修正。

如需相關資訊,請參閱 #getCurrentLocation(String, LocationRequest, CancellationSignal, Executor, Consumer)

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

此頁面的部分是根據 Android 開放原始碼專案所建立和共用的工作進行修改,並根據 Creative Commons 2.5 屬性授權中所述的詞彙使用。

適用於