QGeoCoordinate Class

QGeoCoordinate 类定义了地球表面的地理位置。更多

头文件: #include <QGeoCoordinate>
CMake: find_package(Qt6 REQUIRED COMPONENTS Positioning)
target_link_libraries(mytarget PRIVATE Qt6::Positioning)
qmake: QT += positioning

公共类型

enum CoordinateFormat { Degrees, DegreesWithHemisphere, DegreesMinutes, DegreesMinutesWithHemisphere, DegreesMinutesSeconds, DegreesMinutesSecondsWithHemisphere }
enum CoordinateType { InvalidCoordinate, Coordinate2D, Coordinate3D }

属性

公共职能

QGeoCoordinate()
QGeoCoordinate(double latitude, double longitude)
QGeoCoordinate(double latitude, double longitude, double altitude)
QGeoCoordinate(const QGeoCoordinate &other)
(since 6.2) QGeoCoordinate(QGeoCoordinate &&other)
~QGeoCoordinate()
double altitude() const
QGeoCoordinate atDistanceAndAzimuth(qreal distance, qreal azimuth, qreal distanceUp = 0.0) const
qreal azimuthTo(const QGeoCoordinate &other) const
qreal distanceTo(const QGeoCoordinate &other) const
bool isValid() const
double latitude() const
double longitude() const
void setAltitude(double altitude)
void setLatitude(double latitude)
void setLongitude(double longitude)
(since 6.2) void swap(QGeoCoordinate &other)
QString toString(QGeoCoordinate::CoordinateFormat format = DegreesMinutesSecondsWithHemisphere) const
QGeoCoordinate::CoordinateType type() const
(since 6.2) QGeoCoordinate &operator=(QGeoCoordinate &&other)
QGeoCoordinate &operator=(const QGeoCoordinate &other)
bool operator!=(const QGeoCoordinate &lhs, const QGeoCoordinate &rhs)
QDataStream &operator<<(QDataStream &stream, const QGeoCoordinate &coordinate)
bool operator==(const QGeoCoordinate &lhs, const QGeoCoordinate &rhs)
QDataStream &operator>>(QDataStream &stream, QGeoCoordinate &coordinate)

详细说明

QGeoCoordinate 由纬度、经度和可选的高度定义。

使用type() 可以确定坐标是二维坐标(只有经度和纬度)还是三维坐标(有经度、纬度和高度)。使用distanceTo() 和azimuthTo() 计算坐标之间的距离和方位。

坐标值应使用 WGS84 基准。有关地理术语的更多信息,请参阅有关坐标的文章和有关大地测量系统(包括 WGS84)的文章。

方位角在这里等同于以真北为基准的罗盘方位。

自 Qt XML 5.5 起,该类是Q_GADGET 。它可直接用于 C++ 和 QML

成员类型文档

enum QGeoCoordinate::CoordinateFormat

定义toString() 的可能格式化选项。

常量说明
QGeoCoordinate::Degrees0返回十进制度数格式的坐标字符串。
QGeoCoordinate::DegreesWithHemisphere1返回十进制度数格式的坐标字符串,使用 "N"、"S"、"E "或 "W "表示坐标的半球。
QGeoCoordinate::DegreesMinutes2以度-分格式返回坐标的字符串。
QGeoCoordinate::DegreesMinutesWithHemisphere3返回以度-分格式表示的坐标字符串,使用 "N"、"S"、"E "或 "W "表示坐标的半球。
QGeoCoordinate::DegreesMinutesSeconds4返回以度-分-秒格式表示的坐标字符串。
QGeoCoordinate::DegreesMinutesSecondsWithHemisphere5用 "N"、"S"、"E "或 "W "表示坐标的半球,以度-分-秒格式返回坐标字符串。

另请参阅 toString()。

enum QGeoCoordinate::CoordinateType

定义坐标的类型。

常数说明
QGeoCoordinate::InvalidCoordinate0无效坐标。如果坐标的经纬度值无效,则坐标无效。
QGeoCoordinate::Coordinate2D1具有有效经纬度值的坐标。
QGeoCoordinate::Coordinate3D2具有有效经纬度值和高度值的坐标。

属性文档

altitude : double

该属性表示海拔高度,单位为米。

如果未设置海拔高度,则该属性未定义(qQNaN()) 。

虽然该属性是在 Qt 5.5 中引入的,但相关的访问函数在该类的第一个版本中就已存在。

访问函数:

double altitude() const
void setAltitude(double altitude)

[read-only] isValid : const bool

该属性表示该地理坐标的有效性。

如果longitudelatitude 属性已设置为有效值,则该地理坐标有效。

虽然该属性是在 Qt 5.5 中引入的,但相关的访问函数在该类的第一个版本中就已存在。

访问函数:

bool isValid() const

latitude : double

该属性用十进制度表示纬度。

如果未设置纬度,则该属性未定义(qQNaN()) 。正纬度表示北半球,负纬度表示南半球。设置纬度时,新值应采用WGS84基准格式。

纬度必须在 -90 至 90 之间(含 90)才有效。

虽然该属性是在 Qt 5.5 中引入的,但相关的访问函数在该类的第一个版本中就已存在。

访问函数:

double latitude() const
void setLatitude(double latitude)

longitude : double

该属性用十进制度数表示经度。

如果没有设置经度,则该属性未定义(qQNaN() )。正经度表示东半球,负经度表示西半球。设置经度时,新值应采用WGS84基准格式。

经度必须在 -180 至 180 之间(含 180)才有效。

虽然该属性是在 Qt 5.5 中引入的,但相关的访问函数在该类的第一个版本中就已存在。

访问函数:

double longitude() const
void setLongitude(double longitude)

成员函数文档

QGeoCoordinate::QGeoCoordinate()

构造一个坐标。在调用setLatitude() 和setLongitude() 之前,坐标无效。

QGeoCoordinate::QGeoCoordinate(double latitude, double longitude)

用给定的latitudelongitude 构建一个坐标。

如果纬度不在 -90 至 90 之间(包括 90),或经度不在 -180 至 180 之间(包括 180),则不设置任何值,type() 将是QGeoCoordinate::InvalidCoordinate

另请参见 isValid()。

QGeoCoordinate::QGeoCoordinate(double latitude, double longitude, double altitude)

用给定的latitudelongitudealtitude 构建一个坐标。

如果纬度不在 -90 至 90 之间(包括 90),或经度不在 -180 至 180 之间(包括 180),则不设置任何值,type() 将是QGeoCoordinate::InvalidCoordinate

请注意,altitude 指定的是海拔高度。

另请参见 isValid()。

QGeoCoordinate::QGeoCoordinate(const QGeoCoordinate &other)

根据other 的内容构建坐标。

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

通过从other 移动构建坐标。

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

此函数在 Qt 6.2 中引入。

[noexcept] QGeoCoordinate::~QGeoCoordinate()

销毁坐标对象。

double QGeoCoordinate::altitude() const

返回海拔高度(海拔米)。

如果未设置海拔高度,则返回值未定义。

注: 属性高度的获取函数。

另请参阅 setAltitude() 和type()。

[invokable] QGeoCoordinate QGeoCoordinate::atDistanceAndAzimuth(qreal distance, qreal azimuth, qreal distanceUp = 0.0) const

返回从当前坐标azimuth (或方位)沿大圆移动distance 米后到达的坐标。计算时假定地球为球形。

distanceUp

如果该坐标无效,则返回无效坐标。

注: 可通过元对象系统和 QML 调用此函数。请参阅Q_INVOKABLE

[invokable] qreal QGeoCoordinate::azimuthTo(const QGeoCoordinate &other) const

返回该坐标到other 所指定坐标的方位角(或方位)(以度为单位)。计算中不使用高度。

返回的方位是从原点沿两个坐标之间的大圆到other 的方位。计算时假设地球为球面。

如果该坐标的类型或other 的类型为QGeoCoordinate::InvalidCoordinate ,则返回 0。

注: 可通过元对象系统和 QML 调用此函数。请参见Q_INVOKABLE

[invokable] qreal QGeoCoordinate::distanceTo(const QGeoCoordinate &other) const

返回此坐标到other 指定坐标的距离(以米为单位)。计算中不使用海拔高度。

计算时假定地球为球面,返回两个坐标之间的大圆距离。

如果该坐标的类型或other 的类型为QGeoCoordinate::InvalidCoordinate ,则返回 0。

注: 可通过元对象系统和 QML 调用此函数。请参见Q_INVOKABLE

bool QGeoCoordinate::isValid() const

如果longitudelatitude 有效,则返回true

注: 属性 isValid 的获取函数。

double QGeoCoordinate::latitude() const

以十进制度为单位返回纬度。如果未设置纬度,则返回值未定义。

正纬度表示北半球,负纬度表示南半球。

注: 纬度属性的获取函数。

另请参阅 setLatitude() 和type()。

double QGeoCoordinate::longitude() const

以十进制度为单位返回经度。如果没有设置经度,则返回值未定义。

正经度表示东半球,负经度表示西半球。

注: 经度属性的获取函数。

另请参阅 setLongitude() 和type()。

void QGeoCoordinate::setAltitude(double altitude)

将高度(海拔米)设为altitude

注: 属性altitude 的设置函数。

另请参阅 altitude() 。

void QGeoCoordinate::setLatitude(double latitude)

将纬度(十进制度)设置为latitude 。该值应使用 WGS84 基准。

纬度值必须在 -90 至 90 之间(含 90)才有效。

注: 属性latitude 的设置函数。

另请参阅 latitude() 。

void QGeoCoordinate::setLongitude(double longitude)

将经度(十进制度)设置为longitude 。该值应使用 WGS84 基准。

经度值必须在 -180 至 180 之间(含 180)才有效。

注: 属性longitude 的设置函数。

另请参阅 longitude() 。

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

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

此函数在 Qt 6.2 中引入。

[invokable] QString QGeoCoordinate::toString(QGeoCoordinate::CoordinateFormat format = DegreesMinutesSecondsWithHemisphere) const

以指定的字符串形式返回该坐标(format )。

例如,如果该坐标的纬度为 -27.46758,经度为 153.027892,海拔为 28.1,则根据format 返回这些字符串:

format返回字符串
Degrees-27.46758°, 153.02789°, 28.1m
DegreesWithHemisphere南纬 27.46758°,东经 153.02789°,海拔 28.1 米
DegreesMinutes-27° 28.054', 153° 1.673', 28.1m
DegreesMinutesWithHemisphere南纬 27°28.054', 东经 153°1.673', 28.1 米
DegreesMinutesSeconds-27° 28' 3.2", 153° 1' 40.4", 28.1m
DegreesMinutesSecondsWithHemisphere南纬 27°28'3.2",东经 153°1'40.4",28.1 米

如果未设置高度,则省略高度字段。

如果坐标无效,则返回空字符串。

注: 可通过元对象系统和 QML 调用此函数。请参见Q_INVOKABLE

QGeoCoordinate::CoordinateType QGeoCoordinate::type() const

返回此坐标的类型。

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

Move-assignsother 到此坐标,并返回此坐标的引用。

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

此函数在 Qt 6.2 中引入。

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

为该坐标指定other 并返回该坐标的引用。

相关非会员

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

如果lhs 坐标的经度、纬度或高度与rhs 坐标的经度、纬度或高度不一致,则返回true 。否则返回false

QDataStream &operator<<(QDataStream &stream, const QGeoCoordinate &coordinate)

将给定的coordinate 写入指定的stream

另请参阅 序列化 Qt 数据类型

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

如果lhs 坐标的经度、纬度和高度与rhs 坐标的经度、纬度和高度相同,则返回true 。否则返回false

如果纬度为 +/- 90 度,经度将被忽略。

QDataStream &operator>>(QDataStream &stream, QGeoCoordinate &coordinate)

将坐标从指定的stream 读取到给定的coordinate 中。

另请参阅 序列化 Qt 数据类型

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