在本页

route QML Value Type

路由类型代表一条地理路由。更多

Import Statement: import QtLocation 6.11
Since: QtLocation 5.5

属性

方法

详细描述

路线类型包含路线的高级信息,如路线长度、路线的预计旅行时间,以及在地图上呈现路线基本图像所需的足够信息。

QGeoRoute 对象还包含一个routeSegment 对象列表,该列表更详细地描述了路线的各个分段。

获取路线对象的主要途径是RouteModel

示例

本示例展示了如何在ListView 中显示航线的操纵:

import QtQuick
import QtPositioning
import QtLocation

RouteModel {
    id: routeModel
    // model initialization
}

ListView {
    id: listview
    anchors.fill: parent
    spacing: 10
    model: routeModel.status == RouteModel.Ready ? routeModel.get(0).segments : null
    visible: model ? true : false
    delegate: Row {
        width: parent.width
        spacing: 10
        property bool hasManeuver : modelData.maneuver && modelData.maneuver.valid
        visible: hasManeuver
        Text { text: (1 + index) + "." }
        Text { text: hasManeuver ? modelData.maneuver.instructionText : "" }
    }
}

属性文档

bounds : geoRectangle

只读属性,用于保存包含整个路线的边界框。

distance : real

只读属性,以米为单位保存该路线的覆盖距离。

extendedAttributes : Object [since QtLocation 5.13]

该属性包含路由的扩展属性,是一个地图。这些属性是插件特有的,可以为空。

关于支持哪些属性以及如何使用这些属性,请查阅插件文档

注意,由于QQmlPropertyMap 的限制,无法在 QML 中声明指定属性,属性键和值的分配只能通过 JavaScript 完成。

此属性在 QtLocation 5.13 中引入。

legIndex : int

只读属性,用于保存包含路径的 QtLocation::route::leg 列表中该路径的索引。如果此路由不是整个路由中的一条支路,则索引为-1。

另请参阅 overallRoute

legs : list<route> [since QtLocation 5.12]

返回与此路径相关的路径段。航段是指每两个相邻航点之间的子航段。如果后台不支持这种详细程度,结果可能为空。

此属性在 QtLocation 5.12 中引入。

overallRoute : Route

只读属性,用于保存包含该路径的路由。

path : list<coordinate>

只读属性,用于保存此路线的地理坐标。坐标按照沿此路线段旅行的人穿越的顺序排列。

要访问单个路段,可以使用标准的列表访问器:path.length "表示对象的数量,"path[从零开始的索引]"表示实际的对象。

另请参见 QtPositioning::coordinate

segments : list<routeSegment>

只读属性,用于保存该路由的routeSegment 对象列表。

要访问单个线段,可以使用标准的列表访问器:segments.length "表示对象的数量,而 "segments[从零开始的索引]"则表示实际的对象。

另请参见 routeSegment

travelTime : int

只读属性,用于保存遍历这条路线所需的估计时间,以秒为单位。

方法文档

int segmentsCount()

返回路线中的路段数

另请参见 routeSegment

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