本页内容

Qt Location 地理服务

Qt Location 通过 GeoService 插件提供其大部分功能。本文概述了如何开发一个新的 GeoService 插件。

插件描述

每个插件都由一个 JSON 文件进行描述。该 JSON 文件描述了插件的功能和版本。以下是 OpenStreetMap 插件所用 JSON 文件的示例:

{
    "Keys": ["osm"],
    "Provider": "osm",
    "Version": 100,
    "Experimental": false,
    "Features": [
        "OnlineMappingFeature",
        "OnlineGeocodingFeature",
        "ReverseGeocodingFeature",
        "OnlineRoutingFeature",
        "OnlinePlacesFeature"
    ]
}

各条目的含义如下:

键描述
键插件的唯一名称/键。每个GeoService插件必须拥有一个唯一的名称。
提供商服务的提供商名称。多个插件可能具有相同的名称。在这种情况下,将使用“版本”字符串来进一步区分这些插件。
实验性将服务插件标记为实验性。API 开发人员在实例化 `QGeoServiceProvider::QGeoServiceProvider()` 时,可选择忽略此类插件。
版本插件版本。如果多个插件具有相同的提供程序名称,则将使用版本最高的插件。
功能插件/服务提供的功能列表。每个功能都是QGeoServiceProvider 中相应功能的字符串表示形式。更多详细信息请参阅QGeoServiceProvider::routingFeatures()、QGeoServiceProvider::geocodingFeatures() 和QGeoServiceProvider::placesFeatures()。

实现插件

插件开发者需要继承 QGeoServiceProviderFactory 类,并根据需要继承相应的 ManagerEngine 类以提供具体实现。

继承 QGeoServiceProviderFactory 仅需重写以下方法之一:

如果插件未提供相应引擎,相关函数应返回nullptr 。

QGeoCodingManagerEngine

面向希望为地理编码操作提供支持的 QGeoServiceProvider 插件实现者的接口和便捷方法

QGeoRoutingManagerEngine

面向希望提供地理路由信息访问功能的 QGeoServiceProvider 插件实现者的接口和便捷方法

QPlaceManagerEngine

面向希望提供地点功能访问权限的 QGeoServiceProvider 插件实现者的接口

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