geoCoordinate QML Value Type

地理坐标类型表示并存储地理位置。更多

Import Statement: import QtPositioning

属性

方法

详细说明

该类型是QGeoCoordinate 的 QML 表示法,以latitudelongitudealtitude 属性的形式表示地理位置。latitude 属性指定赤道上下的十进制度数。正纬度表示北半球,负纬度表示南半球。longitude 属性指定东经和西经的十进制度数。正经度表示东半球,负经度表示西半球。altitude 属性指定海拔高度的米数。这些属性共同指定了地球表面或其附近任何地方的三维位置。

isValid 属性可用于测试坐标是否有效。如果一个坐标具有有效的经度和纬度,则该坐标被认为是有效的。不需要有效的高度。纬度必须在 -90 至 90 之间(含 90),经度必须在 -180 至 180 之间(含 180)。

Qt Location 模块中的许多其他类型都使用地理坐标类型,用于指定对象在地图上的位置、设备的当前位置以及许多其他任务。它们还具有许多重要的实用方法,使原本复杂的计算变得简单易用,例如atDistanceAndAzimuth()。

精确度

存储在地理坐标类型中的纬度、经度和海拔属性以双倍表示,精度约为小数点后 16 位,足以指定微米。在azimuthTo() 和distanceTo() 等 geoCoordinate 方法中执行的计算也使用双倍来表示所有中间值,但其球形地球模型固有的不准确性会影响其输出的误差。

使用示例

要创建地理坐标,请使用下面描述的方法之一。在所有情况下,指定altitude 属性都是可选的。

要创建地理坐标值,请使用QtPositioning.coordinate() 函数:

import QtPositioning

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

或作为单独的latitudelongitudealtitude 组件:

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

与 C++ 集成时,请注意从 C++ 传入 QML 的任何QGeoCoordinate 值都会自动转换为地理坐标值,反之亦然。

属性文档

altitude : real

该属性保存海拔高度值(海平面以上米数)。如果未设置该属性,其默认值为 NaN。

有关详细信息,请参阅QGeoCoordinate::altitude 属性。


isValid : bool

该属性表示坐标当前的有效性。如果坐标设置了有效的纬度和经度,则视为有效坐标(不需要海拔高度)。

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

这是一个只读属性。


latitude : real

该属性保存地理位置的纬度值(十进制度)。正纬度表示北半球,负纬度表示南半球。如果未设置该属性,其默认值为 NaN。

更多详情,请参阅QGeoCoordinate::latitude 属性


longitude : real

该属性保存地理位置的经度值(十进制度数)。如果未设置该属性,其默认值为 NaN。

更多详情,请参阅QGeoCoordinate::longitude 属性


方法文档

geoCoordinate atDistanceAndAzimuth(real distance, real azimuth)

返回从distance 米处出发,沿azimuth 度大圆移动所到达的坐标。

计算时假设地球为球面。


real azimuthTo(geoCoordinate other)

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

计算时假定地球为球面。


real distanceTo(geoCoordinate other)

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

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


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