W3cubDocs

/Qt

coordinate QML Basic Type

This type is a QML representation of QGeoCoordinate and represents a geographic position in the form of latitude, longitude and altitude attributes. The latitude attribute specifies the number of decimal degrees above and below the equator. A positive latitude indicates the Northern Hemisphere and a negative latitude indicates the Southern Hemisphere. The longitude attribute specifies the number of decimal degrees east and west. A positive longitude indicates the Eastern Hemisphere and a negative longitude indicates the Western Hemisphere. The altitude attribute specifies the number of meters above sea level. Together, these attributes specify a 3-dimensional position anywhere on or near the Earth's surface.

The isValid attribute can be used to test if a coordinate is valid. A coordinate is considered valid if it has a valid latitude and longitude. A valid altitude is not required. The latitude must be between -90 and 90 inclusive and the longitude must be between -180 and 180 inclusive.

The coordinate type is used by many other types in the Qt Location module, for specifying the position of an object on a Map, the current position of a device and many other tasks. They also feature a number of important utility methods that make otherwise complex calculations simple to use, such as atDistanceAndAzimuth().

Accuracy

The latitude, longitude and altitude attributes stored in the coordinate type are represented as doubles, giving them approximately 16 decimal digits of precision -- enough to specify micrometers. The calculations performed in coordinate's methods such as azimuthTo() and distanceTo() also use doubles for all intermediate values, but the inherent inaccuracies in their spherical Earth model dominate the amount of error in their output.

Example Usage

Use properties of type var to store a coordinate. To create a coordinate use one of the methods described below. In all cases, specifying the altitude attribute is optional.

To create a coordinate value, use the QtPositioning.coordinate() function:

import QtPositioning

Location { coordinate: QtPositioning.coordinate(-27.5, 153.1) }

or as separate latitude, longitude and altitude components:

Location {
    coordinate {
        latitude: -27.5
        longitude: 153.1
    }
}

When integrating with C++, note that any QGeoCoordinate value passed into QML from C++ is automatically converted into a coordinate value, and vice-versa.

Properties

latitude

real latitude

This property holds the latitude value of the geographical position (decimal degrees). A positive latitude indicates the Northern Hemisphere, and a negative latitude indicates the Southern Hemisphere. If the property has not been set, its default value is NaN.

For more details see the QGeoCoordinate::latitude property

longitude

real longitude

This property holds the longitude value of the geographical position (decimal degrees). A positive longitude indicates the Eastern Hemisphere, and a negative longitude indicates the Western Hemisphere If the property has not been set, its default value is NaN.

For more details see the QGeoCoordinate::longitude property

altitude

real altitude

This property holds the altitude value (meters above sea level). If the property has not been set, its default value is NaN.

For more details see the QGeoCoordinate::altitude property

isValid

bool isValid

This property holds the current validity of the coordinate. Coordinates are considered valid if they have been set with a valid latitude and longitude (altitude is not required).

The latitude must be between -90 to 90 inclusive to be considered valid, and the longitude must be between -180 to 180 inclusive to be considered valid.

This is a read-only property.

Methods

distanceTo()

real distanceTo(coordinate other)

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.

azimuthTo()

real azimuth(coordinate other)

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

There is an assumption that the Earth is spherical for the purpose of this calculation.

atDistanceAndAzimuth()

coordinate atDistanceAndAzimuth(real distance, real azimuth)

Returns the coordinate that is reached by traveling distance metres from this coordinate at azimuth degrees along a great-circle.

There is an assumption that the Earth is spherical for the purpose of this calculation.

© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-6.2/qml-coordinate.html