本页内容

route QML Value Type

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

Import Statement: import QtLocation 6.12
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::legs 列表中的索引。如果该路线并非某个总体路线中的路段,则该索引为 -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.