本页内容

QGeoRoute Class

QGeoRoute 类表示两个点之间的路径。更多...

Header: #include <QGeoRoute>
qmake: QT += location

属性

公共函数

QGeoRoute()
QGeoRoute(const QGeoRoute &other)
QGeoRoute(QGeoRoute &&other)
~QGeoRoute()
QGeoRectangle bounds() const
qreal distance() const
QVariantMap extendedAttributes() const
QGeoRouteSegment firstRouteSegment() const
int legIndex() const
QGeoRoute overallRoute() const
QList<QGeoCoordinate> path() const
QString routeId() const
QList<QGeoRoute> routeLegs() const
QList<QGeoRouteSegment> segments() const
qsizetype segmentsCount() const
void setFirstRouteSegment(const QGeoRouteSegment &routeSegment)
void setPath(const QList<QGeoCoordinate> &path)
void setTravelMode(QGeoRouteRequest::TravelMode mode)
QGeoRouteRequest::TravelMode travelMode() const
int travelTime() const
QGeoRoute &operator=(const QGeoRoute &other)

受保护函数

QExplicitlySharedDataPointer<QGeoRoutePrivate> &d()
bool operator!=(const QGeoRoute &lhs, const QGeoRoute &rhs)
bool operator==(const QGeoRoute &lhs, const QGeoRoute &rhs)

详细说明

一个 QGeoRoute 对象包含有关路线的高级信息,例如路线长度、路线的预计行驶时间,以及足以在地图上渲染路线基本图像的信息。

QGeoRoute 对象还包含一组QGeoRouteSegment 对象,这些对象更详细地描述了路线的各个子段。

通常使用QGeoRoutingManager::calculateRoute() 请求路线信息,该方法会返回一个QGeoRouteReply 实例。如果操作成功完成,则可以通过QGeoRouteReply::routes() 访问路线信息。

另请参阅 QGeoRoutingManager 。

属性文档

[read-only] bounds : const QGeoRectangle

该属性存储了包含整个路线的边界框

访问函数:

QGeoRectangle bounds() const

[read-only] distance : const qreal

该属性存储了该路线的行驶距离(单位:米)

访问函数:

qreal distance() const

[read-only] extendedAttributes : const QVariantMap

该属性存储与该路由相关的扩展属性

访问函数:

QVariantMap extendedAttributes() const

[read-only] legIndex : const int

该属性存储了该路线的支线索引

该区段在包含它的QGeoRoute::routeLegs 列表中的索引可用于查找后续区段。

访问函数:

int legIndex() const

[read-only] overallRoute : const QGeoRoute

该属性存储包含此路线段的路线

如果该路线并非某个总体路线中的路段,则该属性将包含一个空路线。

访问函数:

QGeoRoute overallRoute() const

path : QList<QGeoCoordinate>

该属性存储了路线的几何形状

坐标应按沿该路线段行进时经过的顺序列出。

访问函数:

QList<QGeoCoordinate> path() const
void setPath(const QList<QGeoCoordinate> &path)

[read-only] routeId : const QString

该属性存储了此路由的标识符

支持路由更新的服务提供商通常会为路由分配标识符。如果该路由来自此类服务提供商,则更改标识符可能会导致路由更新功能失效。

访问函数:

QString routeId() const

[read-only] routeLegs : const QList<QGeoRoute>

该属性存储多航点路线legs 的相关信息

访问函数:

QList<QGeoRoute> routeLegs() const

[read-only] segments : const QList<QGeoRouteSegment>

该属性包含该路由的QGeoRouteSegment 对象列表

访问函数:

QList<QGeoRouteSegment> segments() const

[read-only] segmentsCount : const qsizetype

该属性存储了路线中的路段数量

访问函数:

qsizetype segmentsCount() const

[read-only] travelTime : const int

该属性存储了穿越此路线预计所需的时间(单位为秒)

访问函数:

int travelTime() const

成员函数文档

QGeoRoute::QGeoRoute()

构建一个路由对象。

[noexcept] QGeoRoute::QGeoRoute(const QGeoRoute &other)

根据other 中的内容构建一个路由对象。

[constexpr noexcept default] QGeoRoute::QGeoRoute(QGeoRoute &&other)

通过Move构造一个QGeoRoute 的实例。

[noexcept] QGeoRoute::~QGeoRoute()

销毁此路线对象。

[protected] QExplicitlySharedDataPointer<QGeoRoutePrivate> &QGeoRoute::d()

返回私有实现。

QGeoRouteSegment QGeoRoute::firstRouteSegment() const

返回该路由中的第一个路由段。

如果该路由没有关联的路由段,则将返回一个无效的路由段。

可以通过 `QGeoRouteSegment::nextRouteSegment` 依次访问其余的路由段。

另请参阅 setFirstRouteSegment()。

void QGeoRoute::setFirstRouteSegment(const QGeoRouteSegment &routeSegment)

将路线中的第一个路段设置为routeSegment 。

另请参阅 firstRouteSegment()。

void QGeoRoute::setTravelMode(QGeoRouteRequest::TravelMode mode)

将此路线的出行模式设置为“mode ”。

该值应为 request().travelModes() 返回的旅行模式之一。

另请参阅 travelMode()。

QGeoRouteRequest::TravelMode QGeoRoute::travelMode() const

返回该路线的出行方式。

该值应为 request().travelModes() 方法返回的出行模式之一。

另请参阅 ` setTravelMode()`。

[noexcept] QGeoRoute &QGeoRoute::operator=(const QGeoRoute &other)

将other 中的内容分配给此路由,并返回对此路由的引用。

相关非成员

[noexcept] bool operator!=(const QGeoRoute &lhs, const QGeoRoute &rhs)

返回路线lhs 和rhs 是否不相同。

[noexcept] bool operator==(const QGeoRoute &lhs, const QGeoRoute &rhs)

返回路线lhs 和rhs 是否相等。

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