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 结果。

limitoffset 结果一起用于实现分页。

如果bounds 不是空值,并且是一个有效的QGeoShape ,它将用于将结果限制为bounds 所包含的结果。

用户负责删除返回的回复对象,不过可以在连接到QGeoCodingManagerEngine::finished() 、QGeoCodingManagerEngine::errorOccurred() 、QGeoCodeReply::finished() 或QGeoCodeReply::errorOccurred() 的插槽中通过deleteLater() 删除。

QLocale QGeoCodingManagerEngine::locale() const

返回用于向地理编码管理器提示结果使用哪种语言的 locale。

另请参阅 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() 。

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