本页内容

QGeoLocation Class

QGeoLocation 类表示有关某个位置的基本信息。更多内容...

头文件: #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

[constexpr noexcept default, 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)

将other 移动到此位置,并返回对此位置的引用。

注意: 被移动的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 。

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