Qt Positioning

Qt Positioning API 通过 QML 和 C++ 接口提供定位信息。

目前,AndroidiOSmacOSLinuxWindows均支持该 API(GPS 接收机作为串行端口提供 NMEA 句子或使用Windows.Devices.Geolocation )。

概述

Qt Positioning API 可让您通过各种可能的来源(包括卫星、wifi 或文本文件)确定位置。这些信息可用于确定地图上的位置等。此外,您还可以使用 API 检索卫星信息并执行区域监控。

使用模块

QML API

模块的 QML 类型可通过QtPositioning 导入。要使用这些类型,请在 .qml 文件中添加以下导入语句:

import QtPositioning

C++ API

使用 Qt 模块的 C++ API 需要直接或通过其他依赖关系与模块库链接。一些编译工具对此提供了专门支持,包括CMakeqmake

使用 CMake 构建

使用find_package() 命令在Qt6 软件包中找到所需的模块组件:

find_package(Qt6 REQUIRED COMPONENTS Positioning)
target_link_libraries(mytarget PRIVATE Qt6::Positioning)

更多详情,请参阅使用 CMake 构建概述。

使用 qmake 构建

要配置模块以便用 qmake 构建,请在项目的 .pro 文件中添加模块作为QT 变量的值:

QT += positioning

权限

从 Qt 6.6 开始,Qt Positioning 模块使用新的QPermission API 来处理location 权限。这意味着 Qt 本身不再查询这些权限,因此需要直接从客户端应用程序进行查询。

有关如何将新的QPermission API 集成到应用程序中的示例,请参阅应用程序权限页面。

文章和指南

示例

参考资料

模块演变

Qt Positioning 的变更列出了 Qt 6 系列 Qt 在模块 API 和功能方面的重要变更。

许可证

Qt Positioning Qt 6 是在Qt 公司的商业许可下提供的。此外,它还以自由软件许可证的形式提供。自 Qt 5.4 起,这些自由软件许可证为GNU Lesser General Public License 第 3 版GNU General Public License 第 2 版。更多详情,请参阅Qt 许可

© 2025 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.