Qt Positioning Android 插件
概述
Qt Positioning Android 插件封装了原生 Android API,并提供定位和卫星信息访问功能。
可通过提供程序名称android 加载该插件。
参数
下表列出了可传递给 Android 插件的参数。
| 参数 | 描述 |
|---|---|
| useMslAltitude | 该参数在 Qt 6.8 中引入。它用于确定插件是否尝试提供以平均海平面 (MSL) 为基准的海拔高度。默认值为false ,这意味着它以 WGS84 格式提供海拔高度。此参数仅适用于 Android 14 及更高版本。更多详细信息请参阅“海拔转换”部分。 |
海拔转换
Android 传统上提供相对于 1984 年世界大地测量系统 (WGS84) 参考椭球的海拔高度。然而,从 Android 14 开始,引入了一个新的AltitudeConverter类。该类允许将 WGS84 海拔高度转换为相对于平均海平面 (MSL) 的海拔高度格式。
如果将useMslAltitude 插件参数设置为true ,且应用程序在Android 14及更高版本上运行,则在位置更新期间获取的QGeoPositionInfo 对象的QGeoCoordinate::altitude 字段将包含MSL海拔高度。
注意:根据 Android文档,转换为海平面高度(MSL)可能需要几秒钟。这意味着,当启用此功能时,lastKnownPosition() 请求的执行时间可能会变长,因为该方法是同步的。其他位置更新请求不受影响。
示例
以下示例演示了如何从 C++ 和 QML 创建Android PositionSource 。
QML
以下代码片段创建了一个不带参数的PositionSource 。海拔高度将以WGS84格式返回。
PositionSource {
name: "android"
}下一个代码片段显式添加了useMslAltitude PluginParameter ,并将其值设置为true 。该PositionSource 将以MSL格式报告海拔高度。
PositionSource {
name: "android"
PluginParameter {
name: "useMslAltitude"
value: true
}
}C++
以下代码片段演示了如何使用 C++ 创建一个以 MSL 格式报告海拔的position source 。
QVariantMap params;
params["useMslAltitude"] = true;
QGeoPositionInfoSource *positionSource = QGeoPositionInfoSource::createSource("android", params, this);© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.