The coordinate type represents and stores a geographic position. 更多...
import 语句: | import QtPositioning 6.5 |
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
().
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 () 和 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.
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.
要创建
coordinate
值,使用
QtPositioning.coordinate()
函数:
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.
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
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
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
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.
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.
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.
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.