本页内容

geoCoordinate QML Value Type

geoCoordinate 类型用于表示和存储地理位置。更多内容...

Import Statement: import QtPositioning

属性

方法

详细说明

该类型是QGeoCoordinate 的QML表示形式,通过latitude 、longitude 和altitude 属性来表示地理位置。latitude 属性指定赤道以北或以南的十进制度数。正纬度表示北半球,负纬度表示南半球。longitude 属性指定东经或西经的十进制度数。 正经度表示东半球,负经度表示西半球。altitude 属性指定海拔高度(以米为单位)。这些属性共同确定了地球表面或附近任意位置的三维坐标。

可通过isValid 属性来验证坐标是否有效。若坐标包含有效的纬度和经度,则被视为有效;高度无需有效。纬度必须在 -90 到 90 之间(包含端点),经度必须在 -180 到 180 之间(包含端点)。

Qt Location 模块中的许多其他类型都会使用geoCoordinate类型,用于指定对象在地图上的位置、设备的当前位置以及完成许多其他任务。该类型还提供了一系列重要的实用方法,使原本复杂的计算变得简单易用,例如atDistanceAndAzimuth()。

精度

存储在 geoCoordinate 类型中的纬度、经度和海拔属性均以 double 类型表示,精度约为 16 位小数——足以精确到微米级。 geoCoordinate 的方法(如azimuthTo() 和distanceTo())中执行的计算也使用 double 类型作为所有中间值,但其球面地球模型固有的不准确性主导了输出结果中的误差量。

用法示例

要创建 geoCoordinate 对象,请使用以下描述的方法之一。在所有情况下,指定altitude 属性均为可选。

要创建 geoCoordinate 值,请使用QtPositioning.coordinate() 函数:

import QtPositioning

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

或者作为独立的latitude 、longitude 和altitude 组件:

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

在与 C++ 集成时,请注意:从 C++ 传递到 QML 的任何 `QGeoCoordinate ` 值都会自动转换为 `geoCoordinate` 值,反之亦然。

属性文档

altitude : real

该属性存储海拔值(以米为单位,相对于海平面)。如果该属性未被设置,其默认值为 NaN。

更多详细信息请参阅QGeoCoordinate::altitude 属性

isValid : bool

该属性存储坐标的当前有效性。如果坐标已设置为有效的纬度和经度(海拔非必需),则视为有效。

纬度必须在 -90 到 90 之间(含 -90 和 90),经度必须在 -180 到 180 之间(含 -180 和 180),才被视为有效。

这是一个只读属性。

latitude : real

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

更多详细信息请参阅QGeoCoordinate::latitude 属性

longitude : real

该属性存储地理位置的经度值(十进制度数)。正经度表示东半球,负经度表示西半球。如果未设置该属性,其默认值为 NaN。

更多详细信息请参阅QGeoCoordinate::longitude 属性

方法文档

geoCoordinate atDistanceAndAzimuth(real distance, real azimuth)

返回从该坐标点出发,沿大圆方向以azimuth 度角行进distance 米后到达的坐标。

本计算基于地球为球体的假设。

real azimuthTo(geoCoordinate other)

返回从该坐标到由other 指定的坐标之间的方位角(或航向),单位为度。计算中不考虑高度。

此计算基于地球为球体的假设。

real distanceTo(geoCoordinate other)

返回从该坐标到由other 指定的坐标之间的距离(单位:米)。计算中不考虑海拔高度。

此计算返回两个坐标之间的大圆距离,并假设地球为球体以进行此计算。

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