TencentLocationManager class
腾讯定位管理器。
支持在同一应用内创建多个实例,各实例独立维护自己的事件流(onLocationChanged / onLocationError / onStatusChanged / onOrientationChanged)和启停状态 (startContinuousLocation / stopContinuousLocation、前台服务、后台任务等)。
多实例语义边界
事件分发到哪个实例是隔离的:A 实例的订阅者只会收到 A 实例触发的回调,与同 时存在的 B 实例互不干扰。但部分配置类参数在底层是应用范围共享的,多个实例 同时使用时,后调用的一方会覆盖先前的设置,包括但不限于:
- startContinuousLocation 传入的 TencentLocationRequest(间隔、坐标系、 逆地址等所有字段);
- changeCallbackInterval;
- getLastLocation(返回的是应用最近一次的定位结果,不区分由哪个实例产生)。
因此不建议在同一应用内同时启动多个连续定位实例并期望它们各自使用不同的 TencentLocationRequest。多实例的典型用途是:把单次定位、连续定位、地理围栏 这类语义不同的能力拆到不同管理器里,便于在业务侧分别控制生命周期。
Constructors
- TencentLocationManager()
- 创建一个新的定位管理器。
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String
-
本实例的唯一 ID。
no setter
-
onLocationChanged
→ Stream<
TencentLocation> -
连续定位结果流。
no setter
-
onLocationError
→ Stream<
TencentLocationError> -
定位错误流。
no setter
-
onOrientationChanged
→ Stream<
TencentDeviceOrientation> -
设备朝向事件流。订阅即开启监听,取消订阅即停止。
no setter
-
onStatusChanged
→ Stream<
TencentDeviceStatus> -
设备状态事件流。订阅即开启监听,取消订阅即停止。
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
changeCallbackInterval(
Duration interval) → Future< void> - 动态修改连续定位的回调频率。用于修改 Android 系统定位回调频率,可以降低系统定位次数的统计, 同时会修改 onLocationChanged 的回调频率,二者保持一致。
-
disableForeground(
{bool removeNotification = true}) → Future< void> - 关闭前台定位服务。
-
dismissIosHeadingCalibrationDisplay(
) → Future< void> - 关闭系统弹出的朝向校准提示面板。
-
dispose(
) → Future< void> - 释放本实例资源。
-
enableForeground(
{required int notificationId, required String channelId, required String title, required String text, String? smallIconResourceName}) → Future< void> - 启用前台定位服务,让定位在应用进入后台时也能继续运行。
-
getLastLocation(
) → Future< TencentLocation?> - 获取最近一次的定位结果。
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setIosExtraData(
String key, String value) → Future< void> - 在本实例上设置 iOS 专属的附加数据。
-
startBackgroundLocationTask(
{Map< String, Object?> ? wantAgentInfo}) → Future<void> - 开始后台定位任务。
-
startContinuousLocation(
TencentLocationRequest request) → Future< void> - 开始连续定位。结果通过 onLocationChanged 获取。
-
startSingleLocation(
TencentLocationRequest request) → Future< TencentLocation> - 请求单次定位。结果直接由返回的 Future 发出,不经过 onLocationChanged。
-
stopBackgroundLocationTask(
) → Future< void> - 停止后台定位任务。
-
stopContinuousLocation(
) → Future< void> - 停止连续定位。重复调用是安全的。
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited