本页内容

QGeoCodingManagerEngine Class

QGeoCodingManagerEngine 类为希望支持地理编码操作的QGeoServiceProvider 插件开发者提供了接口和便捷方法。更多内容...

Header: #include <QGeoCodingManagerEngine>
qmake: QT += location
Inherits: QObject

公共函数

QGeoCodingManagerEngine(const QVariantMap &parameters, QObject *parent = nullptr)
virtual ~QGeoCodingManagerEngine()
virtual QGeoCodeReply *geocode(const QGeoAddress &address, const QGeoShape &bounds)
virtual QGeoCodeReply *geocode(const QString &address, int limit, int offset, const QGeoShape &bounds)
QLocale locale() const
QString managerName() const
int managerVersion() const
virtual QGeoCodeReply *reverseGeocode(const QGeoCoordinate &coordinate, const QGeoShape &bounds)
void setLocale(const QLocale &locale)

信号

void errorOccurred(QGeoCodeReply *reply, QGeoCodeReply::Error error, const QString &errorString = QString())
void finished(QGeoCodeReply *reply)

详细说明

注意: 对于后端类,不保证 源代码或二进制兼容性。仅保证该 API 可与开发时所基于的 Qt 版本配合使用。不过,API 变更仅会在次要版本(如 6.6、6.7 等)中进行。

在默认实现中,supportsGeocoding() 和 supportsReverseGeocoding() 返回 false,而geocode() 和reverseGeocode() 会导致QGeoCodeReply::UnsupportedOptionError 异常。

如果服务提供商支持地理编码,子类应提供geocode() 的实现,并在调用geocode() 之前某个时间点调用 setSupportsGeocoding(true)。

同样,如果服务提供商支持反向地理编码,子类应提供reverseGeocode() 的实现,并在调用reverseGeocode() 之前某个时间点调用 setSupportsReverseGeocoding(true)。

QGeoCodingManagerEngine 的子类通常会在内部使用QGeoCodeReply 的子类,以便将任何引擎特有的数据(例如基于网络服务的QNetworkReply 对象)添加到引擎所使用的QGeoCodeReply 实例中。

另请参阅 QGeoCodingManager 。

成员函数文档

[explicit] QGeoCodingManagerEngine::QGeoCodingManagerEngine(const QVariantMap &parameters, QObject *parent = nullptr)

使用指定的parent 构建一个新的引擎,并通过parameters 向引擎传递任何与实现相关的数据。

[virtual noexcept] QGeoCodingManagerEngine::~QGeoCodingManagerEngine()

会损坏这台发动机。

[signal] void QGeoCodingManagerEngine::errorOccurred(QGeoCodeReply *reply, QGeoCodeReply::Error error, const QString &errorString = QString())

当在处理reply 时检测到错误时,将发出此信号。随后可能会发出QGeoCodingManagerEngine::finished()信号。

该错误将由错误代码 `error` 描述。如果 `errorString ` 不为空,则其中将包含该错误的文本描述。

该信号与QGeoCodeReply::errorOccurred() 将同时发出。

注意:请 勿在连接到此信号的槽中删除reply 对象。请改用deleteLater()。

[signal] void QGeoCodingManagerEngine::finished(QGeoCodeReply *reply)

当reply 处理完成时,会发出此信号。

如果 reply::error() 等于QGeoCodeReply::NoError ,则表示处理已成功完成。

该信号和QGeoCodeReply::finished() 将同时发出。

注意:请 勿在连接到此信号的槽中删除reply 对象。请改用deleteLater()。

[virtual] QGeoCodeReply *QGeoCodingManagerEngine::geocode(const QGeoAddress &address, const QGeoShape &bounds)

开始对address 进行地理编码。地理编码是指根据给定地址查找对应坐标的过程。

将返回一个QGeoCodeReply 对象,该对象可用于管理地理编码操作并返回操作结果。

该引擎和返回的QGeoCodeReply 对象将发出信号,指示操作是否完成或是否发生错误。

如果 supportsGeocoding() 返回 false,则会触发一个QGeoCodeReply::UnsupportedOptionError 。

操作完成后,可以使用QGeoCodeReply::locations() 检索结果,结果将包含一组QGeoLocation 对象。这些对象代表坐标和地址数据的组合。

结果中返回的地址数据可能与 `address` 不同。这种情况通常发生在地理编码服务后端使用不同的地址规范形式,或者 `address ` 仅部分填写时。

如果bounds 不为空且是一个有效的QGeoShape ,则将使用它将结果限制为位于bounds 范围内的条目。当address 仅部分填写时,此功能尤为有用,因为服务将尝试对指定数据的所有匹配项进行地理编码。

用户有责任删除返回的回复对象,虽然也可以在连接到QGeoCodingManagerEngine::finished()、QGeoCodingManagerEngine::errorOccurred()、QGeoCodeReply::finished() 或QGeoCodeReply::errorOccurred() 的插槽中,通过deleteLater() 来执行此操作。

[virtual] QGeoCodeReply *QGeoCodingManagerEngine::geocode(const QString &address, int limit, int offset, const QGeoShape &bounds)

开始对与address 匹配的位置进行地理编码。

将返回一个QGeoCodeReply 对象,该对象可用于管理地理编码操作并返回操作结果。

该引擎和返回的QGeoCodeReply 对象将发出信号,指示操作是否完成或是否发生错误。

操作完成后,可以使用QGeoCodeReply::locations() 检索结果,结果将包含一个QGeoLocation 对象列表。这些对象代表坐标和地址数据的组合。

如果limit 的值为 -1,则将返回完整的结果集;否则,最多返回limit 个结果。

offset 参数用于要求地理编码服务不返回前offset 个结果。

limit 和offset 结果将结合使用以实现分页。

如果bounds 不为空且为有效的QGeoShape ,则将使用它将结果限制为bounds 所包含的结果。

用户有责任删除返回的回复对象,尽管这也可以在与QGeoCodingManagerEngine::finished()、QGeoCodingManagerEngine::errorOccurred()、QGeoCodeReply::finished() 或QGeoCodeReply::errorOccurred() 关联的槽中,通过deleteLater() 来完成。

QLocale QGeoCodingManagerEngine::locale() const

返回用于提示此地理编码管理器应使用哪种语言显示结果的区域设置。

另请参阅 setLocale()。

QString QGeoCodingManagerEngine::managerName() const

返回该引擎实现用于将其与其他插件提供的实现区分开的名称。

managerName() 与managerVersion() 的组合在所有插件实现中应保持唯一。

int QGeoCodingManagerEngine::managerVersion() const

返回此引擎实现的版本号。

managerName() 与 managerVersion() 的组合在所有插件实现中应具有唯一性。

[virtual] QGeoCodeReply *QGeoCodingManagerEngine::reverseGeocode(const QGeoCoordinate &coordinate, const QGeoShape &bounds)

开始对coordinate 进行反向地理编码。反向地理编码是指根据给定的坐标查找对应地址的过程。

将返回一个QGeoCodeReply 对象,该对象可用于管理反向地理编码操作并返回操作结果。

该引擎和返回的QGeoCodeReply 对象将发出信号,指示操作是否完成或是否发生错误。

如果 supportsReverseGeocoding() 返回 false,则会触发一个QGeoCodeReply::UnsupportedOptionError 。

此时,可以使用QGeoCodeReply::locations() 来检索结果,该结果将包含一组QGeoLocation 对象。这些对象代表坐标和地址数据的组合。

结果中返回的坐标数据可能与coordinate 不同。这种情况通常发生在反向地理编码服务后端将坐标调整得更接近匹配的地址时,或者后端返回了多个详细程度的结果时。

如果反向地理编码服务后端返回多个结果,则会按具体程度从高到低的顺序提供。这种情况通常发生在后端被配置为跨多个详细级别进行反向地理编码时。例如,某些服务会针对街道地址、城市、州和国家返回地址与坐标的配对数据。

如果 `bounds ` 不为空且为有效的 `QGeoShape `,则将使用它将结果限制为位于 `bounds` 范围内的结果。

用户有责任删除返回的回复对象,尽管也可以在与QGeoCodingManagerEngine::finished()、QGeoCodingManagerEngine::errorOccurred()、QGeoCodeReply::finished() 或QGeoCodeReply::errorOccurred() 关联的槽中,通过deleteLater() 来完成此操作。

void QGeoCodingManagerEngine::setLocale(const QLocale &locale)

将此管理器使用的区域设置为locale 。

如果此地理编码管理器支持以不同语言返回结果,则结果将以locale 指定的语言返回。

如果未设置此区域设置,则默认使用系统区域设置。

另请参阅 locale()。

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