QGeoLocation Class

QGeoLocation 类表示位置的基本信息。更多

Header: #include <QGeoLocation>
CMake: find_package(Qt6 REQUIRED COMPONENTS Positioning)
target_link_libraries(mytarget PRIVATE Qt6::Positioning)
qmake: QT += positioning

公共函数

QGeoLocation()
QGeoLocation(const QGeoLocation &other)
(since 6.2) QGeoLocation(QGeoLocation &&other)
~QGeoLocation()
QGeoAddress address() const
(since 6.2) QGeoShape boundingShape() const
QGeoCoordinate coordinate() const
QVariantMap extendedAttributes() const
bool isEmpty() const
void setAddress(const QGeoAddress &address)
(since 6.2) void setBoundingShape(const QGeoShape &boundingShape)
void setCoordinate(const QGeoCoordinate &coordinate)
void setExtendedAttributes(const QVariantMap &data)
(since 6.2) void swap(QGeoLocation &other)
(since 6.2) QGeoLocation &operator=(QGeoLocation &&other)
QGeoLocation &operator=(const QGeoLocation &other)
size_t qHash(const QGeoLocation &location, size_t seed = 0)
bool operator!=(const QGeoLocation &lhs, const QGeoLocation &rhs)
bool operator==(const QGeoLocation &lhs, const QGeoLocation &rhs)

详细说明

QGeoLocation 包含一个坐标和相应的地址,以及一个可选的边界形状,边界形状是查看位置时建议显示的区域。

成员函数文档

QGeoLocation::QGeoLocation()

构造一个新的位置对象。

QGeoLocation::QGeoLocation(const QGeoLocation &other)

构建一个other

[noexcept, since 6.2] QGeoLocation::QGeoLocation(QGeoLocation &&other)

通过移动other 构建一个地理位置对象。

注意: 移动后的 QGeoLocation 对象只能被销毁或赋值。调用析构函数或赋值操作符之外的其他函数的效果未定义。

此函数在 Qt 6.2 中引入。

[noexcept] QGeoLocation::~QGeoLocation()

销毁位置对象。

QGeoAddress QGeoLocation::address() const

返回位置的地址。

另请参阅 setAddress()。

[since 6.2] QGeoShape QGeoLocation::boundingShape() const

返回一个边界形状,表示在查看该位置时建议显示的区域。

例如,建筑物的位置可能有一个以建筑物为中心的区域,但该区域要足够大,以显示其周围的地理环境。

注: 该方法在 Qt6 中引入,取代了 boundingBox() 方法。它返回一个QGeoShape ,而不是QGeoRectangle 。使用QGeoShape::boundingGeoRectangle() 获取形状的边界QGeoRectangle

此函数在 Qt 6.2 中引入。

另请参阅 setBoundingShape()。

QGeoCoordinate QGeoLocation::coordinate() const

返回位置的坐标。

另请参见 setCoordinate()。

QVariantMap QGeoLocation::extendedAttributes() const

返回与该位置相关的扩展属性。扩展属性取决于后端,也可能取决于位置。

另请参阅 setExtendedAttributes()。

bool QGeoLocation::isEmpty() const

如果位置坐标为invalid ,且所有其他位置字段为空,则返回true 。否则返回false

void QGeoLocation::setAddress(const QGeoAddress &address)

设置位置的address

另请参阅 address()。

[since 6.2] void QGeoLocation::setBoundingShape(const QGeoShape &boundingShape)

设置位置的boundingShape

此函数在 Qt 6.2 中引入。

另请参阅 boundingShape()。

void QGeoLocation::setCoordinate(const QGeoCoordinate &coordinate)

设置位置的coordinate

另请参阅 coordinate()。

void QGeoLocation::setExtendedAttributes(const QVariantMap &data)

使用data 中指定的参数设置位置的扩展属性。

另请参阅 extendedAttributes() 。

[noexcept, since 6.2] void QGeoLocation::swap(QGeoLocation &other)

将该位置与other 互换。该操作速度非常快,而且从未出现过故障。

此功能在 Qt 6.2 中引入。

[noexcept, since 6.2] QGeoLocation &QGeoLocation::operator=(QGeoLocation &&other)

Move-assingsother 到该位置,并返回对该位置的引用。

注意: QGeoLocation 移动的对象只能被销毁或赋值。调用析构函数或赋值操作符之外的其他函数的效果未定义。

此函数在 Qt 6.2 中引入。

QGeoLocation &QGeoLocation::operator=(const QGeoLocation &other)

为该位置指定other 并返回对该位置的引用。

相关非会员

[noexcept] size_t qHash(const QGeoLocation &location, size_t seed = 0)

返回location 的哈希值,使用seed 进行计算。

注意: 哈希值不考虑扩展属性。这意味着,两个地理位置对象如果仅在扩展属性上存在差异,将提供相似的哈希值。

bool operator!=(const QGeoLocation &lhs, const QGeoLocation &rhs)

如果lhs 位置不等于rhs ,则返回true ,否则返回false

bool operator==(const QGeoLocation &lhs, const QGeoLocation &rhs)

如果lhs 位置等于rhs ,则返回true ,否则返回false

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