Qt Positioning

The Qt Positioning API provides positioning information via QML and C++ interfaces.

Currently, the API is supported on Android , iOS , macOS , Linux ,和 Windows (with GPS receivers exposed as a serial port providing NMEA sentences or using Windows.Devices.Geolocation ).

概述

The Qt Positioning API lets you to determine a position by using a variety of possible sources, including satellite, wifi, or text files. That information can then be used to, for example, determine a position on a map. In addition, you can use to the API to retrieve satellite information and perform area based monitoring.

使用模块

QML API

模块的 QML 类型是可用的透过 QtPositioning 导入。要使用类型,添加以下 import 语句到 .qml 文件:

import QtPositioning
					

C++ API

使用 Qt 模块的 C++ API 要求直接 (或透过其它依赖) 链接到模块库。几个构建工具对此有专用支持,包括 CMake and qmake .

构建采用 CMake

使用 find_package() 命令定位所需模块组件在 Qt6 包:

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

更多细节,见 构建采用 CMake 概述。

采用 qmake 构建

要配置采用 qmake 构建模块,添加模块作为值为 QT 变量在工程的 .pro 文件:

QT += positioning
					

Permissions

Starting from Qt 6.6, the Qt Positioning module uses new QPermission API to handle location permissions. This means that Qt itself no longer queries for these permissions, so this needs to be done directly from the client application.

请参考 应用程序权限 page for an example of how to integrate the new QPermission API into the application.

文章和指南

范例

参考

模块演变

Qt Positioning 的变化 列出了 Qt 的 Qt 6 系列在模块 API 和功能上所做出的重要改变。

许可

Qt Positioning 在商业许可下是可用的来自 Qt 公司 。此外,它在自由软件许可下也是可用的。从 Qt 5.4 起,这些自由软件许可是 GNU LGPL (次一般公共许可) 第 3 版 ,或 GNU GPL (一般公共许可) 第 2 版 。见 Qt 许可 进一步了解细节。