本页内容

Location QML Type

“位置”类型用于存储位置数据。更多内容...

Import Statement: import QtPositioning

属性

详细说明

位置类型代表从人类角度理解的地理“位置”。它由特定的coordinate 、address 和bounding shape 组成。bounding shape 表示查看该位置时建议显示的区域。

“位置”类型最常见于搜索模型(如GeocodeModel )的内部。当GeocodeModel 针对给定查询返回所找到的位置列表时,它会将这些位置以Location对象的形式呈现。

用法示例

以下示例展示了如何声明一个简单的 Location 对象:

Location {
    coordinate {
        latitude: -27.3
        longitude: 153.1
    }
    address: Address {
        ...
    }
}

属性文档

address : Address

该属性存储了该位置的地址,可用于获取该位置的地址详细信息。

boundingShape : geoShape [since QtPositioning 6.2]

该属性存储了显示位置时建议使用的区域。例如,一栋建筑的位置可能有一个以该建筑为中心的区域,但该区域足够大,足以显示其周边的地理环境。

注意:该 属性在 Qt6 中引入,以取代 boundingBox 属性。它返回的是geoShape ,而非geoRectangle 。请使用QGeoShape::boundingGeoRectangle() 来获取形状的边界geoRectangle 。

若需将返回的形状转换为特定类型,请结合使用geoShape 的type 属性与QtPositioning 中的便捷方法(如QtPositioning.shapeToRectangle())。

该属性在 QtPositioning 6.2 中引入。

coordinate : coordinate

该属性存储了该位置的确切地理坐标,可用于获取该位置的纬度、经度和海拔。

extendedAttributes : VariantMap

该属性存储了此位置的扩展属性。扩展属性取决于后端,也可能取决于位置。

location : QGeoLocation

有关如何使用此属性在 C++ 和 QML 之间进行交互的详细信息,请参阅“C++ 与 QML 代码之间的接口”。

注意:此 属性会更新整个地理位置信息,因此使用它将导致所有其他属性的绑定失效。

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