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
返回用于向地理编码管理器提示结果使用何种语言的 locale。
另请参阅 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() 。
© 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.