coordinate QML Value Type

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

Import Statement: import QtPositioning

详细说明

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

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

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

精确度

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

使用示例

使用var 类型的属性来存储coordinate 。要创建coordinate ,请使用下面描述的方法之一。在所有情况下,指定altitude 属性都是可选的。

要创建coordinate 值,请使用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 值都会自动转换为coordinate 值,反之亦然。

属性

纬度

real latitude

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

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

经度

real longitude

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

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

高度

real altitude

该属性用于保存高度值(海拔米)。如果未设置该属性,其默认值为 NaN。

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

有效

bool isValid

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

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

这是一个只读属性。

方法

距离()

real distanceTo(coordinate other)

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

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

方位角

real azimuth(coordinate other)

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

计算时假定地球为球面。

atDistanceAndAzimuth()

coordinate atDistanceAndAzimuth(real distance, real azimuth)

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

计算时假设地球为球面。

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