QGeoCoordinate Class

The QGeoCoordinate class defines a geographical position on the surface of the Earth. 更多...

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

公共类型

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

特性

公共函数

  QGeoCoordinate (QGeoCoordinate && other )
  QGeoCoordinate (const QGeoCoordinate & other )
  QGeoCoordinate (double latitude , double longitude , double altitude )
  QGeoCoordinate (double latitude , double longitude )
  QGeoCoordinate ()
QGeoCoordinate & operator= (QGeoCoordinate && other )
QGeoCoordinate & operator= (const 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 )
QString toString (QGeoCoordinate::CoordinateFormat format = DegreesMinutesSecondsWithHemisphere) const
QGeoCoordinate::CoordinateType type () const
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 )

详细描述

A QGeoCoordinate is defined by latitude, longitude, and optionally, altitude.

使用 type () to determine whether a coordinate is a 2D coordinate (has latitude and longitude only) or 3D coordinate (has latitude, longitude and altitude). Use distanceTo () 和 azimuthTo () to calculate the distance and bearing between coordinates.

The coordinate values should be specified using the WGS84 datum. For more information on geographical terms see this article on coordinates and another on geodetic systems including WGS84.

Azimuth in this context is equivalent to a compass bearing based on true north.

This class is a Q_GADGET since Qt 5.5. It can be directly used from C++ and QML .

成员类型文档编制

enum QGeoCoordinate:: CoordinateFormat

Defines the possible formatting options for toString ().

常量 描述
QGeoCoordinate::Degrees 0 Returns a string representation of the coordinates in decimal degrees format.
QGeoCoordinate::DegreesWithHemisphere 1 Returns a string representation of the coordinates in decimal degrees format, using 'N', 'S', 'E' or 'W' to indicate the hemispheres of the coordinates.
QGeoCoordinate::DegreesMinutes 2 Returns a string representation of the coordinates in degrees-minutes format.
QGeoCoordinate::DegreesMinutesWithHemisphere 3 Returns a string representation of the coordinates in degrees-minutes format, using 'N', 'S', 'E' or 'W' to indicate the hemispheres of the coordinates.
QGeoCoordinate::DegreesMinutesSeconds 4 Returns a string representation of the coordinates in degrees-minutes-seconds format.
QGeoCoordinate::DegreesMinutesSecondsWithHemisphere 5 Returns a string representation of the coordinates in degrees-minutes-seconds format, using 'N', 'S', 'E' or 'W' to indicate the hemispheres of the coordinates.

另请参阅 toString ().

enum QGeoCoordinate:: CoordinateType

Defines the types of a coordinate.

常量 描述
QGeoCoordinate::InvalidCoordinate 0 An invalid coordinate. A coordinate is invalid if its latitude or longitude values are invalid.
QGeoCoordinate::Coordinate2D 1 A coordinate with valid latitude and longitude values.
QGeoCoordinate::Coordinate3D 2 A coordinate with valid latitude and longitude values, and also an altitude value.

特性文档编制

[since 5.5] altitude : double

This property holds the altitude in meters above sea level.

The property is undefined ( qQNaN ()) if the altitude has not been set.

While this property is introduced in Qt 5.5, the related accessor functions exist since the first version of this class.

该特性在 Qt 5.5 引入。

访问函数:

double altitude () const
void setAltitude (double altitude )

[read-only, since 5.5] isValid : const bool

This property holds the validity of this geo coordinate.

The geo coordinate is valid if the longitude and latitude properties have been set to valid values.

While this property is introduced in Qt 5.5, the related accessor functions exist since the first version of this class.

该特性在 Qt 5.5 引入。

访问函数:

bool isValid () const

[since 5.5] latitude : double

This property holds the latitude in decimal degrees.

The property is undefined ( qQNaN ()) if the latitude has not been set. A positive latitude indicates the Northern Hemisphere, and a negative latitude indicates the Southern Hemisphere. When setting the latitude the new value should be in the WGS84 datum format.

To be valid, the latitude must be between -90 to 90 inclusive.

While this property is introduced in Qt 5.5, the related accessor functions exist since the first version of this class.

该特性在 Qt 5.5 引入。

访问函数:

double latitude () const
void setLatitude (double latitude )

[since 5.5] longitude : double

This property holds the longitude in decimal degrees.

The property is undefined ( qQNaN ()) if the longitude has not been set. A positive longitude indicates the Eastern Hemisphere, and a negative longitude indicates the Western Hemisphere. When setting the longitude the new value should be in the WGS84 datum format.

To be valid, the longitude must be between -180 to 180 inclusive.

While this property is introduced in Qt 5.5, the related accessor functions exist since the first version of this class.

该特性在 Qt 5.5 引入。

访问函数:

double longitude () const
void setLongitude (double longitude )

成员函数文档编制

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

Constructs a coordinate by moving from other .

注意: The moved-from QGeoCoordinate object can only be destroyed or assigned to. The effect of calling other functions than the destructor or one of the assignment operators is undefined.

该函数在 Qt 6.2 引入。

QGeoCoordinate:: QGeoCoordinate (const QGeoCoordinate & other )

Constructs a coordinate from the contents of other .

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

Constructs a coordinate with the given latitude , longitude and altitude .

If the latitude is not between -90 to 90 inclusive, or the longitude is not between -180 to 180 inclusive, none of the values are set and the type () will be QGeoCoordinate::InvalidCoordinate .

注意, altitude specifies the meters above sea level.

另请参阅 isValid ().

QGeoCoordinate:: QGeoCoordinate ( double latitude , double longitude )

Constructs a coordinate with the given latitude and longitude .

If the latitude is not between -90 to 90 inclusive, or the longitude is not between -180 to 180 inclusive, none of the values are set and the type () will be QGeoCoordinate::InvalidCoordinate .

另请参阅 isValid ().

QGeoCoordinate:: QGeoCoordinate ()

Constructs a coordinate. The coordinate will be invalid until setLatitude () 和 setLongitude () have been called.

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

移动赋值 other to this coordinate and returns a reference to this coordinate.

注意: The moved-from QGeoCoordinate object can only be destroyed or assigned to. The effect of calling other functions than the destructor or one of the assignment operators is undefined.

该函数在 Qt 6.2 引入。

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

赋值 other to this coordinate and returns a reference to this coordinate.

QGeoCoordinate:: ~QGeoCoordinate ()

Destroys the coordinate object.

double QGeoCoordinate:: altitude () const

Returns the altitude (meters above sea level).

The return value is undefined if the altitude has not been set.

注意: getter 函数对于特性 altitude .

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

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

Returns the coordinate that is reached by traveling distance meters from the current coordinate at azimuth (or bearing) along a great-circle. There is an assumption that the Earth is spherical for the purpose of this calculation.

The altitude will have distanceUp added to it.

Returns an invalid coordinate if this coordinate is invalid.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

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

Returns the azimuth (or bearing) in degrees from this coordinate to the coordinate specified by other . Altitude is not used in the calculation.

The bearing returned is the bearing from the origin to other along the great-circle between the two coordinates. There is an assumption that the Earth is spherical for the purpose of this calculation.

Returns 0 if the type of this coordinate or the type of other is QGeoCoordinate::InvalidCoordinate .

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

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

Returns the distance (in meters) from this coordinate to the coordinate specified by other . Altitude is not used in the calculation.

This calculation returns the great-circle distance between the two coordinates, with an assumption that the Earth is spherical for the purpose of this calculation.

Returns 0 if the type of this coordinate or the type of other is QGeoCoordinate::InvalidCoordinate .

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

bool QGeoCoordinate:: isValid () const

返回 true longitude and latitude are valid.

注意: getter 函数对于特性 isValid .

double QGeoCoordinate:: latitude () const

Returns the latitude, in decimal degrees. The return value is undefined if the latitude has not been set.

A positive latitude indicates the Northern Hemisphere, and a negative latitude indicates the Southern Hemisphere.

注意: getter 函数对于特性 latitude .

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

double QGeoCoordinate:: longitude () const

Returns the longitude, in decimal degrees. The return value is undefined if the longitude has not been set.

A positive longitude indicates the Eastern Hemisphere, and a negative longitude indicates the Western Hemisphere.

注意: getter 函数对于特性 longitude .

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

void QGeoCoordinate:: setAltitude ( double altitude )

Sets the altitude (meters above sea level) to altitude .

注意: setter 函数对于特性 altitude .

另请参阅 altitude ().

void QGeoCoordinate:: setLatitude ( double latitude )

Sets the latitude (in decimal degrees) to latitude . The value should be in the WGS84 datum.

To be valid, the latitude must be between -90 to 90 inclusive.

注意: setter 函数对于特性 latitude .

另请参阅 latitude ().

void QGeoCoordinate:: setLongitude ( double longitude )

Sets the longitude (in decimal degrees) to longitude . The value should be in the WGS84 datum.

To be valid, the longitude must be between -180 to 180 inclusive.

注意: setter 函数对于特性 longitude .

另请参阅 longitude ().

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

Returns this coordinate as a string in the specified format .

For example, if this coordinate has a latitude of -27.46758, a longitude of 153.027892 and an altitude of 28.1, these are the strings returned depending on format :

format Returned string
Degrees -27.46758°, 153.02789°, 28.1m
DegreesWithHemisphere 27.46758° S, 153.02789° E, 28.1m
DegreesMinutes -27° 28.054', 153° 1.673', 28.1m
DegreesMinutesWithHemisphere 27° 28.054 S', 153° 1.673' E, 28.1m
DegreesMinutesSeconds -27° 28' 3.2", 153° 1' 40.4", 28.1m
DegreesMinutesSecondsWithHemisphere 27° 28' 3.2" S, 153° 1' 40.4" E, 28.1m

The altitude field is omitted if no altitude is set.

If the coordinate is invalid, an empty string is returned.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

QGeoCoordinate::CoordinateType QGeoCoordinate:: type () const

Returns the type of this coordinate.

相关非成员

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

返回 true if latitude, longitude, or altitude of the lhs coordinate are not identical to those of the rhs coordinate. Otherwise returns false .

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

写入给定 coordinate 到指定 stream .

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

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

返回 true if the latitude, longitude and altitude of the lhs coordinate are the same as those of the rhs coordinate. Otherwise returns false .

The longitude will be ignored if the latitude is +/- 90 degrees.

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

Reads a coordinate from the specified stream 进给定 coordinate .

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