语言

LocationManager.RequestLocationUpdates 方法

定义

重载

名称 说明
RequestLocationUpdates(String, LocationRequest, PendingIntent)

使用 LocationRequest提供的 PendingIntent和回调从指定的提供程序注册位置更新。

RequestLocationUpdates(Int64, Single, Criteria, PendingIntent)

使用通过给定条件选择的提供程序和通过提供的 PendingIntent回调注册位置更新。

RequestLocationUpdates(String, LocationRequest, IExecutor, ILocationListener)

使用 LocationRequest指定提供程序和指定 Executor回调注册位置更新。

RequestLocationUpdates(String, Int64, Single, PendingIntent)

使用命名提供程序注册位置更新,并通过提供的 PendingIntent回调进行传递。

RequestLocationUpdates(String, Int64, Single, ILocationListener)

使用给定参数注册给定提供程序的位置更新,并在调用线程上 Looper 注册回调。

RequestLocationUpdates(Int64, Single, Criteria, ILocationListener, Looper)

使用通过给定条件选择的提供程序和指定 Looper回调注册位置更新。

RequestLocationUpdates(Int64, Single, Criteria, IExecutor, ILocationListener)

使用通过给定条件选择的提供程序和指定 Executor回调注册位置更新。

RequestLocationUpdates(String, Int64, Single, ILocationListener, Looper)

使用给定参数注册给定提供程序的位置更新,以及指定 Looper参数的回调。

RequestLocationUpdates(String, Int64, Single, IExecutor, ILocationListener)

使用命名提供程序注册位置更新,并在指定的 Executor提供程序上注册回调。

RequestLocationUpdates(String, LocationRequest, PendingIntent)

使用 LocationRequest提供的 PendingIntent和回调从指定的提供程序注册位置更新。

[Android.Runtime.Register("requestLocationUpdates", "(Ljava/lang/String;Landroid/location/LocationRequest;Landroid/app/PendingIntent;)V", "GetRequestLocationUpdates_Ljava_lang_String_Landroid_location_LocationRequest_Landroid_app_PendingIntent_Handler", ApiSince=31)]
public virtual void RequestLocationUpdates(string provider, Android.Locations.LocationRequest locationRequest, Android.App.PendingIntent pendingIntent);
[<Android.Runtime.Register("requestLocationUpdates", "(Ljava/lang/String;Landroid/location/LocationRequest;Landroid/app/PendingIntent;)V", "GetRequestLocationUpdates_Ljava_lang_String_Landroid_location_LocationRequest_Landroid_app_PendingIntent_Handler", ApiSince=31)>]
abstract member RequestLocationUpdates : string * Android.Locations.LocationRequest * Android.App.PendingIntent -> unit
override this.RequestLocationUpdates : string * Android.Locations.LocationRequest * Android.App.PendingIntent -> unit

参数

provider
String

列出的提供程序 #getAllProviders()

locationRequest
LocationRequest

包含位置参数的位置请求

pendingIntent
PendingIntent

发送位置更新的挂起意向

特性

注解

使用 LocationRequest提供的 PendingIntent和回调从指定的提供程序注册位置更新。

传递的挂起意向将包含回调信息的额外内容。 用于额外项的键和 #KEY_LOCATION_CHANGED#KEY_PROVIDER_ENABLED。 有关值的信息,请参阅每个额外键的文档。

若要注销位置更新,请使用 #removeUpdates(PendingIntent)。

Java文档android.location.LocationManager.requestLocationUpdates(java.lang.String, android.location.LocationRequest, android.app.PendingIntent)。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

RequestLocationUpdates(Int64, Single, Criteria, PendingIntent)

使用通过给定条件选择的提供程序和通过提供的 PendingIntent回调注册位置更新。

[Android.Runtime.Register("requestLocationUpdates", "(JFLandroid/location/Criteria;Landroid/app/PendingIntent;)V", "GetRequestLocationUpdates_JFLandroid_location_Criteria_Landroid_app_PendingIntent_Handler")]
public virtual void RequestLocationUpdates(long minTimeMs, float minDistanceM, Android.Locations.Criteria criteria, Android.App.PendingIntent pendingIntent);
[<Android.Runtime.Register("requestLocationUpdates", "(JFLandroid/location/Criteria;Landroid/app/PendingIntent;)V", "GetRequestLocationUpdates_JFLandroid_location_Criteria_Landroid_app_PendingIntent_Handler")>]
abstract member RequestLocationUpdates : int64 * single * Android.Locations.Criteria * Android.App.PendingIntent -> unit
override this.RequestLocationUpdates : int64 * single * Android.Locations.Criteria * Android.App.PendingIntent -> unit

参数

minTimeMs
Int64

位置更新之间的最短时间间隔(以毫秒为单位)

minDistanceM
Single

位置更新之间的最小距离(以米为单位)

criteria
Criteria

包含用于为位置更新选择适当提供程序的参数

pendingIntent
PendingIntent

发送位置更新的挂起意向

特性

例外

如果条件为 null,则为

如果意向为 null

如果不存在合适的权限,则为

注解

使用通过给定条件选择的提供程序和通过提供的 PendingIntent回调注册位置更新。

注意:由于 Android KitKat,条件请求将始终使用 #FUSED_PROVIDER。

有关此方法工作原理的详细信息,请参阅 #requestLocationUpdates(String, long, float, PendingIntent) 。

此成员已弃用。 改 #requestLocationUpdates(String, long, float, PendingIntent) 用显式选择提供程序。

Java文档android.location.LocationManager.requestLocationUpdates(long, float, android.location.Criteria, android.app.PendingIntent)。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

RequestLocationUpdates(String, LocationRequest, IExecutor, ILocationListener)

使用 LocationRequest指定提供程序和指定 Executor回调注册位置更新。

[Android.Runtime.Register("requestLocationUpdates", "(Ljava/lang/String;Landroid/location/LocationRequest;Ljava/util/concurrent/Executor;Landroid/location/LocationListener;)V", "GetRequestLocationUpdates_Ljava_lang_String_Landroid_location_LocationRequest_Ljava_util_concurrent_Executor_Landroid_location_LocationListener_Handler", ApiSince=31)]
public virtual void RequestLocationUpdates(string provider, Android.Locations.LocationRequest locationRequest, Java.Util.Concurrent.IExecutor executor, Android.Locations.ILocationListener listener);
[<Android.Runtime.Register("requestLocationUpdates", "(Ljava/lang/String;Landroid/location/LocationRequest;Ljava/util/concurrent/Executor;Landroid/location/LocationListener;)V", "GetRequestLocationUpdates_Ljava_lang_String_Landroid_location_LocationRequest_Ljava_util_concurrent_Executor_Landroid_location_LocationListener_Handler", ApiSince=31)>]
abstract member RequestLocationUpdates : string * Android.Locations.LocationRequest * Java.Util.Concurrent.IExecutor * Android.Locations.ILocationListener -> unit
override this.RequestLocationUpdates : string * Android.Locations.LocationRequest * Java.Util.Concurrent.IExecutor * Android.Locations.ILocationListener -> unit

参数

provider
String

列出的提供程序 #getAllProviders()

locationRequest
LocationRequest

包含位置参数的位置请求

executor
IExecutor

执行程序处理侦听器回调

listener
ILocationListener

接收位置更新的侦听器

特性

注解

使用 LocationRequest指定提供程序和指定 Executor回调注册位置更新。

每个唯一侦听器/提供程序对只能注册一个请求,因此具有相同提供程序和侦听器的任何后续请求都将覆盖所有关联的参数。 同一侦听器可以跨多个提供程序使用,每个提供程序有不同的请求。

可能需要一些时间才能接收第一个位置更新,具体取决于设备查找到的条件。 为了利用缓存的位置,应用程序可以考虑使用 #getLastKnownLocation(String) 或 #getCurrentLocation(String, LocationRequest, CancellationSignal, Executor, Consumer) 改用。

有关各种请求参数的说明以及它们如何影响接收的位置,请参阅 LocationRequest 文档。

如果应用程序希望被动观察来自所有提供程序的位置更新,请使用 。#PASSIVE_PROVIDER 此提供程序不会打开或修改活动位置提供程序,因此无需谨慎使用最小时间和最小距离参数。 但是,如果应用程序对位置更新(如网络活动)执行繁重的工作,则应针对位置请求设置显式最快的时间间隔,以防另一个应用程序启用具有极快更新的位置提供程序。

如果已禁用所选提供程序,则位置更新将停止,并且将发送提供程序可用性更新。 再次启用提供程序后,将发送另一个提供程序可用性更新,位置更新将恢复。

从 #GPS_PROVIDER 中返回的位置与设备内的主要 GNSS 天线位置有关。 #getGnssAntennaInfos() 可用于确定与 Android 坐标系相关的 GNSS 天线位置,并在必要时在它们之间进行转换。 这通常仅适用于高准确度应用程序。

调用位置回调时,系统将代表应用程序保留一段时间的唤醒锁,但不会无限期地保留。 如果应用程序需要在位置回调中长时间运行的唤醒锁,则应自行获取它。

垃圾邮件位置请求会耗尽系统资源,并且系统已采取预防措施,以确保此行为永远不会导致多个位置,而不是使用一个位置请求来实现,该请求的间隔是一直保留的等效间隔。 作为此缓解的一部分,面向 Android S 及更高版本的应用程序可能通过其侦听器接收缓存或历史位置。 这些位置永远不会早于位置请求的间隔。

若要注销位置更新,请使用 #removeUpdates(LocationListener)。

Java文档android.location.LocationManager.requestLocationUpdates(java.lang.String, android.location.LocationRequest, java.util.concurrent.Executor, android.location.LocationListener)。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

RequestLocationUpdates(String, Int64, Single, PendingIntent)

使用命名提供程序注册位置更新,并通过提供的 PendingIntent回调进行传递。

[Android.Runtime.Register("requestLocationUpdates", "(Ljava/lang/String;JFLandroid/app/PendingIntent;)V", "GetRequestLocationUpdates_Ljava_lang_String_JFLandroid_app_PendingIntent_Handler")]
public virtual void RequestLocationUpdates(string provider, long minTimeMs, float minDistanceM, Android.App.PendingIntent pendingIntent);
[<Android.Runtime.Register("requestLocationUpdates", "(Ljava/lang/String;JFLandroid/app/PendingIntent;)V", "GetRequestLocationUpdates_Ljava_lang_String_JFLandroid_app_PendingIntent_Handler")>]
abstract member RequestLocationUpdates : string * int64 * single * Android.App.PendingIntent -> unit
override this.RequestLocationUpdates : string * int64 * single * Android.App.PendingIntent -> unit

参数

provider
String

列出的提供程序 #getAllProviders()

minTimeMs
Int64

位置更新之间的最短时间间隔(以毫秒为单位)

minDistanceM
Single

位置更新之间的最小距离(以米为单位)

pendingIntent
PendingIntent

发送位置更新的挂起意向

特性

例外

如果提供程序为 null 或此设备上不存在,则为

如果意向为 null

如果不存在合适的权限,则为

注解

使用命名提供程序注册位置更新,并通过提供的 PendingIntent回调进行传递。

有关此方法工作原理的详细信息,请参阅 #requestLocationUpdates(String, LocationRequest, PendingIntent) 。

Java文档android.location.LocationManager.requestLocationUpdates(java.lang.String, long, float, android.app.PendingIntent)。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

RequestLocationUpdates(String, Int64, Single, ILocationListener)

使用给定参数注册给定提供程序的位置更新,并在调用线程上 Looper 注册回调。

[Android.Runtime.Register("requestLocationUpdates", "(Ljava/lang/String;JFLandroid/location/LocationListener;)V", "GetRequestLocationUpdates_Ljava_lang_String_JFLandroid_location_LocationListener_Handler")]
public virtual void RequestLocationUpdates(string provider, long minTimeMs, float minDistanceM, Android.Locations.ILocationListener listener);
[<Android.Runtime.Register("requestLocationUpdates", "(Ljava/lang/String;JFLandroid/location/LocationListener;)V", "GetRequestLocationUpdates_Ljava_lang_String_JFLandroid_location_LocationListener_Handler")>]
abstract member RequestLocationUpdates : string * int64 * single * Android.Locations.ILocationListener -> unit
override this.RequestLocationUpdates : string * int64 * single * Android.Locations.ILocationListener -> unit

参数

provider
String

列出的提供程序 #getAllProviders()

minTimeMs
Int64

位置更新之间的最短时间间隔(以毫秒为单位)

minDistanceM
Single

位置更新之间的最小距离(以米为单位)

listener
ILocationListener

接收位置更新的侦听器

特性

例外

如果提供程序为 null 或此设备上不存在,则为

如果侦听器为 null,则为

如果调用线程没有 Looper

如果不存在合适的权限,则为

注解

使用给定参数注册给定提供程序的位置更新,并在调用线程上 Looper 注册回调。

有关此方法工作原理的详细信息,请参阅 #requestLocationUpdates(String, LocationRequest, Executor, LocationListener) 。

在 Jellybean 之前,minTime 参数只是一个提示,并且某些位置提供程序实现忽略了它。 但是,对于 Jellybean 和更高版本,Android 兼容设备必须同时观察 minTime 和 minDistance 参数。

Java文档android.location.LocationManager.requestLocationUpdates(java.lang.String, long, float, android.location.LocationListener)。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

RequestLocationUpdates(Int64, Single, Criteria, ILocationListener, Looper)

使用通过给定条件选择的提供程序和指定 Looper回调注册位置更新。

[Android.Runtime.Register("requestLocationUpdates", "(JFLandroid/location/Criteria;Landroid/location/LocationListener;Landroid/os/Looper;)V", "GetRequestLocationUpdates_JFLandroid_location_Criteria_Landroid_location_LocationListener_Landroid_os_Looper_Handler")]
public virtual void RequestLocationUpdates(long minTimeMs, float minDistanceM, Android.Locations.Criteria criteria, Android.Locations.ILocationListener listener, Android.OS.Looper? looper);
[<Android.Runtime.Register("requestLocationUpdates", "(JFLandroid/location/Criteria;Landroid/location/LocationListener;Landroid/os/Looper;)V", "GetRequestLocationUpdates_JFLandroid_location_Criteria_Landroid_location_LocationListener_Landroid_os_Looper_Handler")>]
abstract member RequestLocationUpdates : int64 * single * Android.Locations.Criteria * Android.Locations.ILocationListener * Android.OS.Looper -> unit
override this.RequestLocationUpdates : int64 * single * Android.Locations.Criteria * Android.Locations.ILocationListener * Android.OS.Looper -> unit

参数

minTimeMs
Int64

位置更新之间的最短时间间隔(以毫秒为单位)

minDistanceM
Single

位置更新之间的最小距离(以米为单位)

criteria
Criteria

包含用于为位置更新选择适当提供程序的参数

listener
ILocationListener

接收位置更新的侦听器

looper
Looper

一个循环器对象,其消息队列将用于实现回调机制,或为 null 在调用线程上发出回调

特性

例外

如果条件为 null,则为

如果侦听器为 null,则为

如果不存在合适的权限,则为

注解

使用通过给定条件选择的提供程序和指定 Looper回调注册位置更新。

注意:由于 Android KitKat,条件请求将始终使用 #FUSED_PROVIDER。

有关此方法工作原理的详细信息,请参阅 #requestLocationUpdates(String, LocationRequest, Executor, LocationListener) 。

此成员已弃用。 改 #requestLocationUpdates(String, long, float, LocationListener, Looper) 用显式选择提供程序。

Java文档android.location.LocationManager.requestLocationUpdates(long, float, android.location.Criteria, android.location.LocationListener, android.os.Looper)。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

RequestLocationUpdates(Int64, Single, Criteria, IExecutor, ILocationListener)

使用通过给定条件选择的提供程序和指定 Executor回调注册位置更新。

[Android.Runtime.Register("requestLocationUpdates", "(JFLandroid/location/Criteria;Ljava/util/concurrent/Executor;Landroid/location/LocationListener;)V", "GetRequestLocationUpdates_JFLandroid_location_Criteria_Ljava_util_concurrent_Executor_Landroid_location_LocationListener_Handler", ApiSince=30)]
public virtual void RequestLocationUpdates(long minTimeMs, float minDistanceM, Android.Locations.Criteria criteria, Java.Util.Concurrent.IExecutor executor, Android.Locations.ILocationListener listener);
[<Android.Runtime.Register("requestLocationUpdates", "(JFLandroid/location/Criteria;Ljava/util/concurrent/Executor;Landroid/location/LocationListener;)V", "GetRequestLocationUpdates_JFLandroid_location_Criteria_Ljava_util_concurrent_Executor_Landroid_location_LocationListener_Handler", ApiSince=30)>]
abstract member RequestLocationUpdates : int64 * single * Android.Locations.Criteria * Java.Util.Concurrent.IExecutor * Android.Locations.ILocationListener -> unit
override this.RequestLocationUpdates : int64 * single * Android.Locations.Criteria * Java.Util.Concurrent.IExecutor * Android.Locations.ILocationListener -> unit

参数

minTimeMs
Int64

位置更新之间的最短时间间隔(以毫秒为单位)

minDistanceM
Single

位置更新之间的最小距离(以米为单位)

criteria
Criteria

包含用于为位置更新选择适当提供程序的参数

executor
IExecutor

执行程序处理侦听器回调

listener
ILocationListener

接收位置更新的侦听器

特性

注解

使用通过给定条件选择的提供程序和指定 Executor回调注册位置更新。

注意:由于 Android KitKat,条件请求将始终使用 #FUSED_PROVIDER。

有关此方法工作原理的详细信息,请参阅 #requestLocationUpdates(String, LocationRequest, Executor, LocationListener) 。

此成员已弃用。 改 #requestLocationUpdates(String, long, float, Executor, LocationListener) 用显式选择提供程序。

Java文档android.location.LocationManager.requestLocationUpdates(long, float, android.location.Criteria, java.util.concurrent.Executor, android.location.LocationListener)。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

RequestLocationUpdates(String, Int64, Single, ILocationListener, Looper)

使用给定参数注册给定提供程序的位置更新,以及指定 Looper参数的回调。

[Android.Runtime.Register("requestLocationUpdates", "(Ljava/lang/String;JFLandroid/location/LocationListener;Landroid/os/Looper;)V", "GetRequestLocationUpdates_Ljava_lang_String_JFLandroid_location_LocationListener_Landroid_os_Looper_Handler")]
public virtual void RequestLocationUpdates(string provider, long minTimeMs, float minDistanceM, Android.Locations.ILocationListener listener, Android.OS.Looper? looper);
[<Android.Runtime.Register("requestLocationUpdates", "(Ljava/lang/String;JFLandroid/location/LocationListener;Landroid/os/Looper;)V", "GetRequestLocationUpdates_Ljava_lang_String_JFLandroid_location_LocationListener_Landroid_os_Looper_Handler")>]
abstract member RequestLocationUpdates : string * int64 * single * Android.Locations.ILocationListener * Android.OS.Looper -> unit
override this.RequestLocationUpdates : string * int64 * single * Android.Locations.ILocationListener * Android.OS.Looper -> unit

参数

provider
String

列出的提供程序 #getAllProviders()

minTimeMs
Int64

位置更新之间的最短时间间隔(以毫秒为单位)

minDistanceM
Single

位置更新之间的最小距离(以米为单位)

listener
ILocationListener

接收位置更新的侦听器

looper
Looper

处理侦听器回调的循环程序,或使用调用线程的循环器为 null

特性

例外

如果提供程序为 null 或不存在

如果侦听器为 null,则为

如果不存在合适的权限,则为

注解

使用给定参数注册给定提供程序的位置更新,以及指定 Looper参数的回调。

有关此方法工作原理的详细信息,请参阅 #requestLocationUpdates(String, LocationRequest, Executor, LocationListener) 。

在 Jellybean 之前,minTime 参数只是一个提示,并且某些位置提供程序实现忽略了它。 但是,对于 Jellybean 和更高版本,Android 兼容设备必须同时观察 minTime 和 minDistance 参数。

Java文档android.location.LocationManager.requestLocationUpdates(java.lang.String, long, float, android.location.LocationListener, android.os.Looper)。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

RequestLocationUpdates(String, Int64, Single, IExecutor, ILocationListener)

使用命名提供程序注册位置更新,并在指定的 Executor提供程序上注册回调。

[Android.Runtime.Register("requestLocationUpdates", "(Ljava/lang/String;JFLjava/util/concurrent/Executor;Landroid/location/LocationListener;)V", "GetRequestLocationUpdates_Ljava_lang_String_JFLjava_util_concurrent_Executor_Landroid_location_LocationListener_Handler", ApiSince=30)]
public virtual void RequestLocationUpdates(string provider, long minTimeMs, float minDistanceM, Java.Util.Concurrent.IExecutor executor, Android.Locations.ILocationListener listener);
[<Android.Runtime.Register("requestLocationUpdates", "(Ljava/lang/String;JFLjava/util/concurrent/Executor;Landroid/location/LocationListener;)V", "GetRequestLocationUpdates_Ljava_lang_String_JFLjava_util_concurrent_Executor_Landroid_location_LocationListener_Handler", ApiSince=30)>]
abstract member RequestLocationUpdates : string * int64 * single * Java.Util.Concurrent.IExecutor * Android.Locations.ILocationListener -> unit
override this.RequestLocationUpdates : string * int64 * single * Java.Util.Concurrent.IExecutor * Android.Locations.ILocationListener -> unit

参数

provider
String

列出的提供程序 #getAllProviders()

minTimeMs
Int64

位置更新之间的最短时间间隔(以毫秒为单位)

minDistanceM
Single

位置更新之间的最小距离(以米为单位)

executor
IExecutor

执行程序处理侦听器回调

listener
ILocationListener

接收位置更新的侦听器

特性

注解

使用命名提供程序注册位置更新,并在指定的 Executor提供程序上注册回调。

有关此方法工作原理的详细信息,请参阅 #requestLocationUpdates(String, LocationRequest, Executor, LocationListener) 。

在 Jellybean 之前,minTime 参数只是一个提示,并且某些位置提供程序实现忽略了它。 但是,对于 Jellybean 和更高版本,Android 兼容设备必须同时观察 minTime 和 minDistance 参数。

Java文档android.location.LocationManager.requestLocationUpdates(java.lang.String, long, float, java.util.concurrent.Executor, android.location.LocationListener)。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于