QGeoCodingManager Class
QGeoCodingManager 类为地理编码操作提供了支持。更多内容...
| Header: | #include <QGeoCodingManager> |
| qmake: | QT += location |
| Inherits: | QObject |
公共函数
| virtual | ~QGeoCodingManager() |
| QGeoCodeReply * | geocode(const QGeoAddress &address, const QGeoShape &bounds = QGeoShape()) |
| QGeoCodeReply * | geocode(const QString &address, int limit = -1, int offset = 0, const QGeoShape &bounds = QGeoShape()) |
| QLocale | locale() const |
| QString | managerName() const |
| int | managerVersion() const |
| QGeoCodeReply * | reverseGeocode(const QGeoCoordinate &coordinate, const QGeoShape &bounds = QGeoShape()) |
| void | setLocale(const QLocale &locale) |
信号
| void | errorOccurred(QGeoCodeReply *reply, QGeoCodeReply::Error error, const QString &errorString = QString()) |
| void | finished(QGeoCodeReply *reply) |
详细说明
geocode() 和reverseGeocode() 函数返回QGeoCodeReply 对象,这些对象负责管理这些操作,并报告操作结果以及可能发生的任何错误。
geocode() 和reverseGeocode() 函数可用于将QGeoAddress 实例转换为QGeoCoordinate 实例,反之亦然。
geocode() 函数还被重载,以允许用户执行自由文本地理编码操作;如果提供的字符串可以被解释为地址,则可以将其地理编码为坐标信息。
可通过QGeoServiceProvider::geocodingManager() 访问 QGeoCodingManager 的实例。
成员函数文档
[virtual noexcept] QGeoCodingManager::~QGeoCodingManager()
销毁该管理器。
[signal] void QGeoCodingManager::errorOccurred(QGeoCodeReply *reply, QGeoCodeReply::Error error, const QString &errorString = QString())
当在处理reply 时检测到错误时,将发出此信号。随后可能会发出QGeoCodingManager::finished()信号。
该错误将由错误代码 `error` 描述。如果 `errorString ` 不为空,则其中将包含该错误的文本描述。
该信号与QGeoCodeReply::errorOccurred() 将同时发出。
注意:请 勿在连接到此信号的槽中删除reply 对象。请改用deleteLater()。
[signal] void QGeoCodingManager::finished(QGeoCodeReply *reply)
当reply 处理完成后,将发出此信号。
如果 reply::error() 等于QGeoCodeReply::NoError ,则表示处理已成功完成。
该信号和QGeoCodeReply::finished() 将同时发出。
注意:请 勿在连接到此信号的槽中删除reply 对象。请改用deleteLater()。
QGeoCodeReply *QGeoCodingManager::geocode(const QGeoAddress &address, const QGeoShape &bounds = QGeoShape())
开始对address 进行地理编码。地理编码是指根据给定地址查找对应坐标的过程。
将返回一个QGeoCodeReply 对象,该对象可用于管理地理编码操作并返回操作结果。
该管理器和返回的QGeoCodeReply 对象将发出信号,指示操作是否完成或是否发生错误。
如果 supportsGeocoding() 返回 false,则会触发一个QGeoCodeReply::UnsupportedOptionError 事件。
操作完成后,可以使用QGeoCodeReply::locations() 检索结果,结果将由一组QGeoLocation 对象组成。这些对象代表坐标和地址数据的组合。
结果中返回的地址数据可能与 `address` 不同。这种情况通常发生在地理编码服务后端使用的地址规范格式不同,或者 `address ` 仅部分填写的情况下。
如果 `bounds ` 不为空且是一个有效的 `QGeoShape `,则会将其用于将结果限定为位于 `bounds` 范围内的条目。当 `address ` 仅部分填写时,此功能尤为有用,因为服务将尝试对指定数据的所有匹配项进行地理编码。
用户有责任删除返回的回复对象,尽管也可以在连接到QGeoCodingManager::finished()、QGeoCodingManager::errorOccurred()、QGeoCodeReply::finished() 或QGeoCodeReply::errorOccurred() 的插槽中,通过deleteLater() 来执行此操作。
QGeoCodeReply *QGeoCodingManager::geocode(const QString &address, int limit = -1, int offset = 0, const QGeoShape &bounds = QGeoShape())
开始对与address 匹配的位置进行地理编码。
将返回一个QGeoCodeReply 对象,该对象可用于管理地理编码操作并返回操作结果。
该管理器和返回的QGeoCodeReply 对象将发出信号,指示操作是否完成或是否发生错误。
操作完成后,可以使用 `QGeoCodeReply::locations()` 检索结果,结果将包含一个 `QGeoLocation ` 对象列表。这些对象代表坐标和地址数据的组合。
如果 `limit ` 的值为 -1,则将返回完整的结果集;否则,最多返回 `limit ` 个结果。
offset 参数用于要求地理编码服务不返回前offset 个结果。
limit 和offset 结果将结合使用以实现分页。
如果bounds 不为空且为有效的QGeoShape ,则将使用它将结果限制为包含在bounds 中的那些。
用户有责任删除返回的回复对象,尽管也可以在与QGeoCodingManager::finished()、QGeoCodingManager::errorOccurred()、QGeoCodeReply::finished() 或QGeoCodeReply::errorOccurred() 关联的插槽中,通过deleteLater() 来完成此操作。
QLocale QGeoCodingManager::locale() const
返回用于提示此地理编码管理器应使用何种语言显示结果的区域设置。
另请参阅 setLocale()。
QString QGeoCodingManager::managerName() const
返回实现此地理编码管理器行为的引擎名称。
在所有插件实现中,managerName()与managerVersion()的组合应具有唯一性。
int QGeoCodingManager::managerVersion() const
返回实现此地理编码管理器行为的引擎版本。
managerName() 与 managerVersion() 的组合在所有插件实现中应是唯一的。
QGeoCodeReply *QGeoCodingManager::reverseGeocode(const QGeoCoordinate &coordinate, const QGeoShape &bounds = QGeoShape())
开始对coordinate 进行反向地理编码。反向地理编码是指根据给定的坐标查找对应地址的过程。
将返回一个QGeoCodeReply 对象,该对象可用于管理反向地理编码操作并返回操作结果。
该管理器以及返回的QGeoCodeReply 对象将发出信号,指示操作是否完成或是否发生错误。
如果 supportsReverseGeocoding() 返回 false,则会触发一个QGeoCodeReply::UnsupportedOptionError 事件。
此时,可以使用QGeoCodeReply::locations() 检索结果,该结果将包含一组QGeoLocation 对象。这些对象代表坐标和地址数据的组合。
结果中返回的坐标数据可能与coordinate 不同。这通常发生在反向地理编码服务后端将坐标调整得更接近匹配的地址时,或者后端返回了不同详细程度的多个结果时。
如果反向地理编码服务后端返回多个结果,这些结果将按具体程度由高到低的顺序提供。这通常发生在后端配置为跨多个详细级别进行反向地理编码时。例如,某些服务会针对街道地址、城市、州和国家返回地址与坐标的配对数据。
如果 `bounds ` 不为空且为有效的 `QGeoRectangle `,则将使用它将结果限制为仅包含在 `bounds` 范围内的内容。
用户有责任删除返回的回复对象,虽然也可以通过在与QGeoCodingManager::finished()、QGeoCodingManager::errorOccurred()、QGeoCodeReply::finished() 或QGeoCodeReply::errorOccurred() 关联的槽中调用deleteLater() 来完成此操作。
void QGeoCodingManager::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.