{"version":"0.1.0","code":"0000","result":true,"message":"处理成功","errdetail":"","timestamp":1671508879961,"data":{"id":71712162,"title":"7.4 预搜索","slug":"krqxuo","format":"lake","bookId":26046811,"body":null,"body_draft":null,"body_html":"

简介

用户在输入框中输入关键字的同时,给出用户搜索建议,旨在帮助用户快速输入要查询的关键词,高德车机基础版又融合了同步库相关的搜索历史记录(参考搜索历史章节)。返回结果的匹配策略可能是根据名字、地址、行业Tag等信息,除了POI以外还会有热词

注意:

  1. 只有关键词是区县级行政区返回经纬度
  2. 返回的热词结果没有经纬度、地址等信息
  3. 支持精确电话号码搜索(无法模糊匹配)

场景图

时序图

初始化 & 反初始化

关键参数

输入参数

预搜索请求参数

com.autonavi.gbl.search.model.SearchSuggestParam

String com.autonavi.gbl.search.model.SearchSuggestParam.keyword

int com.autonavi.gbl.search.model.SearchSuggestParam.city

Coord2DDouble com.autonavi.gbl.search.model.SearchSuggestParam.poi_loc

搜索模式

com.autonavi.gbl.search.model.SearchMode.SearchMode1

取值

描述

备注

SEARCH_MODE_ONLINE_ADVANCED

在线优先

当在线搜索出现异常,会自动转离线搜索

SEARCH_MODE_OFFLINE_ADVANCED

离线优先

若当前网络是wifi,会切到在线优先方式

SEARCH_MODE_ONLINE_ONLY

仅在线


SEARCH_MODE_OFFLINE_ONLY

仅离线


搜索任务id

taskid外部需自己保证全局唯一

预搜索结果回调观察者

com.autonavi.gbl.search.observer.IGSearchSuggestionObserver

搜索结果回调参数

搜索结果pstResult返回值

pstResult关键信息如表格所示,更多返回信息可参考SearchSuggestResult结构的成员描述。

ArrayList<SearchSuggestTip> com.autonavi.gbl.search.model.SearchSuggestResult.tipList

String com.autonavi.gbl.search.model.SearchSuggestTip.category

String com.autonavi.gbl.search.model.SearchSuggestTip.name

String com.autonavi.gbl.search.model.SearchSuggestTip.address

int com.autonavi.gbl.search.model.SearchSuggestTip.citycode

int com.autonavi.gbl.search.model.SearchSuggestTip.adcode       

String com.autonavi.gbl.search.model.SearchSuggestTip.district

String com.autonavi.gbl.search.model.SearchSuggestTip.poi_tag

深度信息可能包含POI的标签信息,比如:写字楼、住宅区、景点、酒店等。

错误码类型

int

euRet为通用的返回错误码,可详见:

com.autonavi.gbl.util.errorcode.common.Service,

com.autonavi.gbl.util.errorcode.common.ThirdParty,

com.autonavi.gbl.util.errorcode.search.Online,

com.autonavi.gbl.util.errorcode.search.Offline 类型。

核心接口

int com.autonavi.gbl.search.SearchService.suggestionSearch(SearchSuggestParam param, IGSearchSuggestionObserver observer, @SearchMode.SearchMode1 int mode, int taskid)

备注:taskid为搜索发起请求的唯一任务id,由客户端分配,用于标识发起请求,客户端可根据此id调用中断接口,中断搜索请求,详见中断请求描述。

void com.autonavi.gbl.search.observer.IGSearchSuggestionObserver.onGetSuggestionResult(int taskid, int euRet, SearchSuggestResult pstResult)

备注1:发起请求为异步接口,结果通过pstResult返回,返回状态参见euRet。

备注2:请注意observer的生命周期,搜索完成或者手动取消之前,请确保观察者不被释放。


说明:函数详情,请复制函数名称到在线API搜索。

调用示例

// 建议定义成static类型\npublic static class SearchSuggestionObserver implements IGSearchSuggestionObserver {\n    @Override\n    public void onGetSuggestionResult(int taskid, int euRet, SearchSuggestResult stResult) {\n        Log.i(TAG, "onGetSuggestionResult: ");\n        Log.i(TAG, " taskid = " + taskid);\n        Log.i(TAG, " euRet = " + euRet);\n        if (stResult != null) {\n            Log.i(TAG, " result = " + stResult.result);\n            Log.i(TAG, " message = " + stResult.message);\n            Log.i(TAG, " version = " + stResult.version);\n            Log.i(TAG, " timestamp = " + stResult.timestamp);\n\n            if (stResult.tipList != null && stResult.tipList.length > 0) {\n                Log.i(TAG, " address = " + stResult.tipList[0].address);\n                Log.i(TAG, " poiid = " + stResult.tipList[0].poiid);\n                Log.i(TAG, " name = " + stResult.tipList[0].name);\n            }\n\n        }\n    }\n};\n\n// 回调观察者,这边需要上层管理,不要每次发起搜索都new一个,定义成成员变量管理一个即可\nSearchSuggestionObserver searchSuggestionObserver = new SearchSuggestionObserver();

注意:观察者需要上层以内部类形式实现,建议定义成static类型,回调观察者的初始化需要上层管理,不要每次发起搜索都new一个,定义成成员变量管理一个即可。

public class SearchRequest\n{\n\tpublic void doSuggestionSearch()\n    {\n        // 1.确定搜索中心\n        Coord2DDouble poiLoc;\n        poiLoc = getMapCenter(); // 获取地图中心坐标\n\t\tMapDataService mapDataService = ServiceMgr.getBLService(MapDataSingleServiceID); // 获取地图数据服务,com.autonavi.gbl.data.MapDataService\n        adCode = mapDataService.getAdcodeByLonLat(poiLoc.lon, poiLoc.lat);\n        \n        // 2. 构建搜索参数\n        SearchSuggestParam param;\n        param.keyword = "北京大学";  // 替换为输入框输入的搜索关键字\n        param.user_loc = getCarLocation();\n        param.city = adCode;\n        param.offlineAdminCode = adCode;\n        param.adcode = true;\n        param.offlineResultMaxCount = 10;\n        param.sugType = 0;\n        \n        // 3. 生成唯一的任务id\n        taskId = 1;\n        \n        // 发起预搜索\n\t\tint iret = SearchService.suggestionSearch(param, searchSuggestionObserver, SEARCH_MODE_ONLINE_ADVANCED, taskId);\n    }\n    \n\t// 获取自车位当前经纬度\n    private Coord2DDouble getCarLocation()\n    {\n        Coord2DDouble carPos; // 自车位所在2D经度、纬度\n        BizCarControl bizCarControl = getBizCarControl();   // 获取车标类图层控制 com.autonavi.gbl.layer.BizCarControl\n        CarLoc carLoc = bizCarControl.getCarPosition();\n        if (carLoc.vecPathMatchInfo.size() > 0)\n        {\n            carPos.lon = vecPathMatchInfo.get(0).longitude;\n            carPos.lat = vecPathMatchInfo.get(0).latitude;\n        }\n        \n        return carPos;\n    }\n    \n    // 获取地图中心点坐标\n    private Coord2DDouble  getMapCenter()\n    {\n        Coord3DDouble mapCenter3D;\n        Coord2DDouble mapCenter;\n        \n        OperatorPosture operatorPosture = getOperatorPosture(); // 获取地图姿态操作接口, com.autonavi.gbl.map.OperatorPosture\n        mapCenter3D = operatorPosture.getMapCenterByLonLat();\n        \n        mapCenter.lon = mapCenter3D.lon;\n        mapCenter.lat = mapCenter3D.lat;\n        \n        return mapCenter;\n    }\n}
taskId = 1;\nSearchService.abort(taskId);


","body_lake":null,"pub_level":null,"status":"0","updated_at":"2022-12-09 09:21:40","deleted_at":null,"nameSpace":"mnlcaa/v610","browseCount":192,"collectCount":0,"estimateDate":12,"docStatus":0,"permissions":true,"overView":false}}