QPlaceSearchRequest Class

QPlaceSearchRequest 类表示搜索请求的参数集。更多

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

公共类型

enum RelevanceHint { UnspecifiedHint, DistanceHint, LexicalPlaceNameHint }

公共函数

QPlaceSearchRequest()
QPlaceSearchRequest(const QPlaceSearchRequest &other)
~QPlaceSearchRequest()
QList<QPlaceCategory> categories() const
void clear()
int limit() const
QString recommendationId() const
QPlaceSearchRequest::RelevanceHint relevanceHint() const
QGeoShape searchArea() const
QVariant searchContext() const
QString searchTerm() const
void setCategories(const QList<QPlaceCategory> &categories)
void setCategory(const QPlaceCategory &category)
void setLimit(int limit)
void setRecommendationId(const QString &placeId)
void setRelevanceHint(QPlaceSearchRequest::RelevanceHint hint)
void setSearchArea(const QGeoShape &area)
void setSearchContext(const QVariant &context)
void setSearchTerm(const QString &term)
void setVisibilityScope(QLocation::VisibilityScope scope)
QLocation::VisibilityScope visibilityScope() const
QPlaceSearchRequest &operator=(const QPlaceSearchRequest &other)
bool operator!=(const QPlaceSearchRequest &lhs, const QPlaceSearchRequest &rhs)
bool operator==(const QPlaceSearchRequest &lhs, const QPlaceSearchRequest &rhs)

详细说明

典型的搜索请求如下:

QPlaceSearchRequest searchRequest;
searchRequest.setSearchTerm("Fast food"); //search term for what we are interested in

//set a search center
searchRequest.setSearchArea(QGeoCircle(QGeoCoordinate(2.3, 48.87)));

//set a distance hint as a relevancy hint.
//closer places have greater weighting in the ranking of results.
searchRequest.setRelevanceHint(QPlaceSearchRequest::DistanceHint);

//use limit to adjust pagination.
//this limits the number of place results to 5 per page.
searchRequest.setLimit(5);

//provide some categories to narrow down search
QList<QPlaceCategory> categories;
categories << diner << restaurant;
searchRequest.setCategories(categories);

请注意,可以通过设置一个有中心但无半径的圆形搜索区域来指定搜索中心。默认半径设置为-1,表示半径未定义。提供程序会将此理解为可以自由选择自己的默认半径。

QPlaceSearchRequest 主要用于QPlaceManagersearch for places ,但也用于为generating search term suggestions 提供参数。请注意,在这种情况下,可能只有部分参数是相关的。例如,搜索区域有助于缩小相关搜索建议的范围,而相关性提示等其他参数则不太适用。

还要注意的是,提供商支持的参数可能有所不同,例如有些提供商可能不支持分页,而有些提供商则支持;有些提供商可能尊重相关性提示,而有些提供商则可能完全忽略这些提示,详情请查看插件文档

成员类型文档

enum QPlaceSearchRequest::RelevanceHint

定义提示,帮助排名结果。

常数说明
QPlaceSearchRequest::UnspecifiedHint0未指定明确的提示。
QPlaceSearchRequest::DistanceHint1与搜索中心的距离与用户相关。距离较近的地方权重较高。只有在查询中使用圆形搜索区域时,该提示才有用。
QPlaceSearchRequest::LexicalPlaceNameHint2根据名称按字母顺序排列地点与用户相关。

成员函数文档

QPlaceSearchRequest::QPlaceSearchRequest()

默认构造函数。构造一个新的请求对象。

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

构造other 的副本。

[noexcept] QPlaceSearchRequest::~QPlaceSearchRequest()

销毁请求对象。

QList<QPlaceCategory> QPlaceSearchRequest::categories() const

返回搜索请求中使用的类别。只有属于其中一个类别的地点才会被请求视为匹配。

另请参阅 setCategories()。

void QPlaceSearchRequest::clear()

清除搜索请求。

int QPlaceSearchRequest::limit() const

返回要检索的搜索结果的最大数量。

limit 的负值表示未定义。后端提供商可自行选择适当的返回结果数。默认限制为-1。

另请参阅 setLimit()。

QString QPlaceSearchRequest::recommendationId() const

返回用于搜索类似地点推荐的地点 ID。

另请参见 setRecommendationId()。

QPlaceSearchRequest::RelevanceHint QPlaceSearchRequest::relevanceHint() const

返回请求的相关性提示。向提供者提供提示是为了帮助而不是决定结果的排序。例如,提供距离提示可能会使距离较近的地方排名靠前,但这并不一定意味着结果会严格按照距离排序。

另请参见 setRelevanceHint()。

QGeoShape QPlaceSearchRequest::searchArea() const

返回用于限制搜索结果的搜索区域。默认搜索区域是一个无效的QGeoShape ,表示没有定义特定的搜索区域。

另请参阅 setSearchArea() 。

QVariant QPlaceSearchRequest::searchContext() const

返回与该地点搜索请求相关的后台特定附加搜索上下文。搜索上下文通常是作为proposed search results 的一部分设置的。

另请参阅 setSearchContext() 。

QString QPlaceSearchRequest::searchTerm() const

返回搜索词。

另请参见 setSearchTerm()。

void QPlaceSearchRequest::setCategories(const QList<QPlaceCategory> &categories)

设置搜索请求,以便从给定的categories 清单中进行搜索。搜索过程中返回的任何位置都将至少与categories 中的一个匹配。

另请参阅 categories() 和setCategory()。

void QPlaceSearchRequest::setCategory(const QPlaceCategory &category)

将搜索请求设置为通过单个category

另请参阅 setCategories()。

void QPlaceSearchRequest::setLimit(int limit)

将检索结果的最大数量设为limit

另请参阅 limit() 。

void QPlaceSearchRequest::setRecommendationId(const QString &placeId)

设置用于搜索推荐的placeId

另请参阅 recommendationId().

void QPlaceSearchRequest::setRelevanceHint(QPlaceSearchRequest::RelevanceHint hint)

设置搜索地点时使用的相关性hint

另请参阅 relevanceHint()。

void QPlaceSearchRequest::setSearchArea(const QGeoShape &area)

将搜索请求设置为在给定的area 范围内搜索。

另请参阅 searchArea() 。

void QPlaceSearchRequest::setSearchContext(const QVariant &context)

将搜索上下文设置为context

注: 该方法供地理服务插件在返回QPlaceSearchResult::ProposedSearchResult 类型的搜索结果时使用。

后端使用搜索上下文来存储与搜索请求相关的附加搜索上下文。其他相关字段也应填写。例如,如果搜索上下文对文本搜索进行编码,则还应使用setSearchTerm() 设置搜索词。搜索上下文允许保留无法通过Qt Location API 直接访问的其他搜索上下文。

搜索上下文可以是存储在QVariant 中的任何类型。搜索上下文的值不能被应用程序直接使用。

另请参阅 searchContext() 。

void QPlaceSearchRequest::setSearchTerm(const QString &term)

设置搜索term

另请参阅 searchTerm() 。

void QPlaceSearchRequest::setVisibilityScope(QLocation::VisibilityScope scope)

设置搜索地点时使用的可见度scope

另请参阅 visibilityScope()。

QLocation::VisibilityScope QPlaceSearchRequest::visibilityScope() const

返回搜索位置时使用的可见性范围。默认值为QLocation::UnspecifiedVisibility ,表示没有指定明确的范围。搜索时可能会返回任何范围的位置。

另请参阅 setVisibilityScope()。

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

为该搜索请求指定other 并返回对该搜索请求的引用。

相关非会员

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

如果lhs 不等于rhs ,则返回 true,否则返回 false。

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

如果lhs 等于rhs ,则返回 true,否则返回 false。

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