![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtPositioning More...
#include <qgeocoordinate.h>
Public Types | |
| enum | CoordinateType { InvalidCoordinate , Coordinate2D , Coordinate3D } |
| Defines the types of a coordinate. More... | |
| enum | CoordinateFormat { Degrees , DegreesWithHemisphere , DegreesMinutes , DegreesMinutesWithHemisphere , DegreesMinutesSeconds , DegreesMinutesSecondsWithHemisphere } |
| Defines the possible formatting options for toString(). More... | |
| enum class | AltitudeType { Unknown , MSL , WGS84 } |
Public Member Functions | |
| QGeoCoordinate () | |
| Constructs a coordinate. | |
| QGeoCoordinate (double latitude, double longitude) | |
| Constructs a coordinate with the given latitude and longitude. | |
| QGeoCoordinate (double latitude, double longitude, double altitude) | |
| Constructs a coordinate with the given latitude, longitude and altitude. | |
| QGeoCoordinate (const QGeoCoordinate &other) | |
| Constructs a coordinate from the contents of other. | |
| QGeoCoordinate (QGeoCoordinate &&other) noexcept=default | |
| ~QGeoCoordinate () | |
| Destroys the coordinate object. | |
| QGeoCoordinate & | operator= (const QGeoCoordinate &other) |
| Assigns other to this coordinate and returns a reference to this coordinate. | |
| void | swap (QGeoCoordinate &other) noexcept |
| bool | isValid () const |
Returns true if the \l longitude and \l latitude are valid. | |
| CoordinateType | type () const |
| Returns the type of this coordinate. | |
| void | setLatitude (double latitude) |
| Sets the latitude (in decimal degrees) to latitude. | |
| double | latitude () const |
| Returns the latitude, in decimal degrees. | |
| void | setLongitude (double longitude) |
| Sets the longitude (in decimal degrees) to longitude. | |
| double | longitude () const |
| Returns the longitude, in decimal degrees. | |
| void | setAltitude (double altitude) |
| Sets the altitude (in meters) to altitude. | |
| double | altitude () const |
| Returns the altitude in meters. | |
| void | setAltitudeType (AltitudeType typetype) |
| AltitudeType | altitudeType () const |
| Q_INVOKABLE qreal | distanceTo (const QGeoCoordinate &other) const |
| Returns the distance (in meters) from this coordinate to the coordinate specified by other. | |
| Q_INVOKABLE qreal | azimuthTo (const QGeoCoordinate &other) const |
| Returns the azimuth (or bearing) in degrees from this coordinate to the coordinate specified by other. | |
| Q_INVOKABLE QGeoCoordinate | atDistanceAndAzimuth (qreal distancedistance, 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. | |
| Q_INVOKABLE QString | toString (CoordinateFormat formatformat=DegreesMinutesSecondsWithHemisphere) const |
| Returns this coordinate as a string in the specified format. | |
Properties | |
| double | latitude |
| This property holds the latitude in decimal degrees. | |
| double | longitude |
| This property holds the longitude in decimal degrees. | |
| double | altitude |
| This property holds the altitude in meters. | |
| bool | isValid |
| This property holds the validity of this geo coordinate. | |
| AltitudeType | altitudeType |
| This property holds the type of the altitude. | |
Friends | |
| class | QGeoCoordinatePrivate |
| class | QQuickGeoCoordinateAnimation |
| bool | operator== (const QGeoCoordinate &lhs, const QGeoCoordinate &rhs) |
Returns true if the latitude, longitude, altitude and altitude type of the lhs coordinate are the same as those of the rhs coordinate. | |
| bool | operator!= (const QGeoCoordinate &lhs, const QGeoCoordinate &rhs) |
Returns true if latitude, longitude, altitude, or altitude type of the lhs coordinate are not identical to those of the rhs coordinate. | |
| QDebug | operator<< (QDebug dbg, const QGeoCoordinate &coordcoord) |
| QDataStream & | operator<< (QDataStream &streamstream, const QGeoCoordinate &coordinate) |
| Writes the given coordinate to the specified stream. | |
| QDataStream & | operator>> (QDataStream &streamstream, QGeoCoordinate &coordinate) |
| Reads a coordinate from the specified stream into the given coordinate. | |
\inmodule QtPositioning
The QGeoCoordinate class defines a geographical position on the surface of the Earth.
A QGeoCoordinate is defined by latitude, longitude, and optionally, altitude.
Use 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() and 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 \l {http://en.wikipedia.org/wiki/Geographic_coordinate_system}{coordinates} and another on \l {http://en.wikipedia.org/wiki/Geodetic_system}{geodetic systems} including WGS84.
The altitude can be measured from different reference surfaces, for example from the mean sea level (MSL) or from the WGS84 reference ellipsoid. Use altitudeType() to find out which reference surface is used for the altitude value, if it is known.
Azimuth in this context is equivalent to a compass bearing based on true north.
This class is also accessible in QML as \l[QML]{geoCoordinate}.
Definition at line 22 of file qgeocoordinate.h.
|
strong |
Defines the reference surface from which the \l altitude is measured.
\value Unknown The reference surface of the altitude is not known. This is the default value. \value MSL The altitude is measured above the mean sea level (MSL). The mean sea level is usually approximated by a geoid model, such as EGM96 or EGM2008, so this altitude is also known as orthometric height. \value WGS84 The altitude is measured above the \l {http://en.wikipedia.org/wiki/World_Geodetic_System}{WGS84} reference ellipsoid. This altitude is also known as ellipsoidal height.
Not all platforms provide information about the reference surface of the altitude. In such cases the coordinates reported by the positioning sources will have the altitude type set to Unknown.
Use \l {QGeoPositionInfoSource::}{preferredAltitudeType} to select the preferred reference surface for the altitude of the reported positions.
| Enumerator | |
|---|---|
| Unknown | |
| MSL | |
| WGS84 | |
Definition at line 51 of file qgeocoordinate.h.
Defines the possible formatting options for toString().
\value Degrees Returns a string representation of the coordinates in decimal degrees format. \value DegreesWithHemisphere Returns a string representation of the coordinates in decimal degrees format, using 'N', 'S', 'E' or 'W' to indicate the hemispheres of the coordinates. \value DegreesMinutes Returns a string representation of the coordinates in degrees-minutes format. \value DegreesMinutesWithHemisphere Returns a string representation of the coordinates in degrees-minutes format, using 'N', 'S', 'E' or 'W' to indicate the hemispheres of the coordinates. \value DegreesMinutesSeconds Returns a string representation of the coordinates in degrees-minutes-seconds format. \value DegreesMinutesSecondsWithHemisphere 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.
| Enumerator | |
|---|---|
| Degrees | |
| DegreesWithHemisphere | |
| DegreesMinutes | |
| DegreesMinutesWithHemisphere | |
| DegreesMinutesSeconds | |
| DegreesMinutesSecondsWithHemisphere | |
Definition at line 41 of file qgeocoordinate.h.
Defines the types of a coordinate.
\value InvalidCoordinate An invalid coordinate. A coordinate is invalid if its latitude or longitude values are invalid. \value Coordinate2D A coordinate with valid latitude and longitude values. \value Coordinate3D A coordinate with valid latitude and longitude values, and also an altitude value.
| Enumerator | |
|---|---|
| InvalidCoordinate | |
| Coordinate2D | |
| Coordinate3D | |
Definition at line 35 of file qgeocoordinate.h.
| QGeoCoordinate::QGeoCoordinate | ( | ) |
Constructs a coordinate.
The coordinate will be invalid until setLatitude() and setLongitude() have been called.
Definition at line 220 of file qgeocoordinate.cpp.
| 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.
Definition at line 234 of file qgeocoordinate.cpp.
| 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.
Note that altitude specifies the altitude in meters. The altitude type of the constructed coordinate is \l {QGeoCoordinate::AltitudeType}{AltitudeType::Unknown}. Use setAltitudeType() to specify the reference surface of the altitude.
Definition at line 258 of file qgeocoordinate.cpp.
| QGeoCoordinate::QGeoCoordinate | ( | const QGeoCoordinate & | other | ) |
Constructs a coordinate from the contents of other.
Definition at line 271 of file qgeocoordinate.cpp.
|
defaultnoexcept |
Constructs a coordinate by moving from other.
| QGeoCoordinate::~QGeoCoordinate | ( | ) |
Destroys the coordinate object.
Definition at line 313 of file qgeocoordinate.cpp.
| double QGeoCoordinate::altitude | ( | ) | const |
Returns the altitude in meters.
The return value is undefined if the altitude has not been set.
The altitude is always given in meters, but it can be measured from different reference surfaces:
\list
Use altitudeType() to determine the reference surface from which the altitude is measured. By default, \l {QGeoCoordinate::AltitudeType} {AltitudeType::Unknown} is used, in which case the reference surface depends on the backend that provides the position updates, as shown in the following table.
\table \header
useMslAltitude plugin parameter is set to true. See \l {Qt Positioning Android plugin} for more details. Starting from Qt 6.13 the behavior can also be controlled with the \l QGeoPositionInfoSource::preferredAltitudeType property. \row Starting from Qt 6.13, the preferred altitude type for these backends can be controlled with the \l QGeoPositionInfoSource::preferredAltitudeType property. The backends will try to report the preferred altitude type, but may fall back to another altitude type if the preferred type is not available. They will set altitudeType() accordingly.
The other backends, such as \l {Qt Positioning GeoClue v2 plugin}{geoclue2} or wasm, have no reliable way to determine the type of the returned altitude. The underlying platform APIs do not specify it, and it can depend on the actual source of the position data. These backends will always report \l altitudeType() as \l {QGeoCoordinate::}{AltitudeType::Unknown}.
Definition at line 496 of file qgeocoordinate.cpp.
| QGeoCoordinate::AltitudeType QGeoCoordinate::altitudeType | ( | ) | const |
Returns the altitude type of this coordinate. The altitude type specifies the reference surface from which the altitude() is measured.
The default value is \l {QGeoCoordinate::AltitudeType}{AltitudeType::Unknown}.
Definition at line 524 of file qgeocoordinate.cpp.
| 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.
Definition at line 646 of file qgeocoordinate.cpp.
| 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.
Definition at line 592 of file qgeocoordinate.cpp.
| 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.
Definition at line 559 of file qgeocoordinate.cpp.
| bool QGeoCoordinate::isValid | ( | ) | const |
Returns true if the \l longitude and \l latitude are valid.
Definition at line 352 of file qgeocoordinate.cpp.
| 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.
Definition at line 382 of file qgeocoordinate.cpp.
| 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.
Definition at line 409 of file qgeocoordinate.cpp.
| QGeoCoordinate & QGeoCoordinate::operator= | ( | const QGeoCoordinate & | other | ) |
Assigns other to this coordinate and returns a reference to this coordinate.
Move-assigns other to this coordinate and returns a reference to this coordinate.
Definition at line 289 of file qgeocoordinate.cpp.
| void QGeoCoordinate::setAltitude | ( | double | altitude | ) |
Sets the altitude (in meters) to altitude.
Use setAltitudeType() to specify the reference surface of the altitude.
Definition at line 508 of file qgeocoordinate.cpp.
| void QGeoCoordinate::setAltitudeType | ( | AltitudeType | type | ) |
Sets the altitude type of this coordinate to type.
The altitude type specifies the reference surface from which the altitude() is measured.
Definition at line 543 of file qgeocoordinate.cpp.
| 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.
Definition at line 395 of file qgeocoordinate.cpp.
| 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.
Definition at line 422 of file qgeocoordinate.cpp.
|
inlinenoexcept |
Definition at line 68 of file qgeocoordinate.h.
| QString QGeoCoordinate::toString | ( | 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:
\table \header
The altitude field is omitted if no altitude is set.
If the coordinate is invalid, an empty string is returned.
Definition at line 695 of file qgeocoordinate.cpp.
| QGeoCoordinate::CoordinateType QGeoCoordinate::type | ( | ) | const |
Returns the type of this coordinate.
Definition at line 361 of file qgeocoordinate.cpp.
|
friend |
Returns true if latitude, longitude, altitude, or altitude type of the lhs coordinate are not identical to those of the rhs coordinate.
Otherwise returns false.
Definition at line 74 of file qgeocoordinate.h.
|
friend |
Writes the given coordinate to the specified stream.
Since Qt 6.13, the \l {altitudeType()}{altitude type} is also written, if the \l {QDataStream::version()}{version} of the stream is QDataStream::Qt_6_13 or later.
Definition at line 115 of file qgeocoordinate.h.
|
friend |
Definition at line 108 of file qgeocoordinate.h.
|
friend |
Returns true if the latitude, longitude, altitude and altitude type 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.
Definition at line 70 of file qgeocoordinate.h.
|
friend |
Reads a coordinate from the specified stream into the given coordinate.
Since Qt 6.13, the \l {altitudeType()}{altitude type} is also read, if the \l {QDataStream::version()}{version} of the stream is QDataStream::Qt_6_13 or later. For older stream versions the altitude type of the coordinate is set to \l {QGeoCoordinate::AltitudeType}{AltitudeType::Unknown}.
Definition at line 119 of file qgeocoordinate.h.
|
friend |
Definition at line 105 of file qgeocoordinate.h.
|
friend |
Definition at line 106 of file qgeocoordinate.h.
|
readwrite |
This property holds the altitude in meters.
The property is undefined (\l {qQNaN()}) if the altitude has not been set.
Use altitudeType() to determine the reference surface from which the altitude is measured.
While this property is introduced in Qt 5.5, the related accessor functions exist since the first version of this class.
Definition at line 28 of file qgeocoordinate.h.
|
readwrite |
This property holds the type of the altitude.
The altitude type specifies the reference surface from which the \l altitude is measured.
The default value is \l {QGeoCoordinate::AltitudeType}{AltitudeType::Unknown}.
Definition at line 30 of file qgeocoordinate.h.
|
read |
This property holds the validity of this geo coordinate.
The geo coordinate is valid if the \l [CPP]{longitude} and \l [CPP]{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.
Definition at line 29 of file qgeocoordinate.h.
|
readwrite |
This property holds the latitude in decimal degrees.
The property is undefined (\l {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 \l {http://en.wikipedia.org/wiki/World_Geodetic_System}{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.
Definition at line 26 of file qgeocoordinate.h.
|
readwrite |
This property holds the longitude in decimal degrees.
The property is undefined (\l {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 \l {http://en.wikipedia.org/wiki/World_Geodetic_System}{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.
Definition at line 27 of file qgeocoordinate.h.