步骑行惯导是在 GPS 定位的基础上融合传感器信号进行位置推导,专为步行和骑行场景优化。
该功能需要同时满足两个条件:具备 GPS 信号且系统传感器模块可用。
自定位 SDK v7.2.8 起,需通过
TencentLocationManager.setDeviceID上传设备唯一标识,用于定位问题排查。
建议全局复用,避免反复创建。
mLocationManager = TencentLocationManager.getInstance(this);
先通过 isDrSupport() 判断设备是否支持,再启动对应模式(步行或骑行):
if (mLocationManager.isDrSupport()) {
int result = mLocationManager.startDrEngine(TencentLocationManager.DR_TYPE_WALK);
if (result == 0) {
// 启动成功
}
}
DR 类型常量:
| 常量 | 说明 |
|---|---|
| 步行惯导 | |
| 骑行惯导 |
与连续定位/单次定位的回调方式不同,惯导结果需要开发者主动调用 API 获取:
TencentLocation drLocation = mLocationManager.getDrPosition();
if (drLocation != null) {
String provider = drLocation.getProvider(); // 定位源
double latitude = drLocation.getLatitude(); // 纬度
double longitude = drLocation.getLongitude(); // 经度
float accuracy = drLocation.getAccuracy(); // 精度(米)
}
建议按固定间隔(如 1 秒)轮询调用
getDrPosition()获取最新位置。
不再使用时及时停止,释放资源:
mLocationManager.terminateDrEngine();
ACCESS_FINE_LOCATION。terminateDrEngine() 停止,再重新启动。TencentLocationListener 回调,必须主动调用 getDrPosition() 获取。isDrSupport() 含义:该方法仅判断设备硬件是否支持惯导,不代表结果一定来自惯导推算。例如室内无 GPS 信号时,返回的可能是普通网络定位结果。
有帮助
没帮助