{"version":"0.1.0","code":"0000","result":true,"message":"处理成功","errdetail":"","timestamp":1671508918359,"data":{"id":71712281,"title":"9.3.4 收藏夹","slug":"ssslmp","format":"lake","bookId":26046811,"body":null,"body_draft":null,"body_html":"
地图选点或者搜索结果选中POI,在POI详情页点 五角星 调用收藏服务的AddFavorite 与 DelFavorite 可以实现POI的收藏点的添加与删除
String com.autonavi.gbl.user.behavior.BehaviorService.addFavorite(FavoriteItem, SyncMode)
String com.autonavi.gbl.user.behavior.BehaviorService.delFavorite(FavoriteBaseItem, SyncMode)
String com.autonavi.gbl.user.behavior.BehaviorService.isFavorite(FavoriteBaseItem)
void com.autonavi.gbl.user.behavior.observer.IBehaviorServiceObserver.notify(SyncEventType, SyncRet)
说明:函数详情,请复制函数名称到在线API搜索
//1. 添加收藏点\nSearchPoi selPoi = searchKeywordResult.poiList[0]; // 搜索结果 \nFavoriteItem item = new FavoriteItem();\nitem.name = selPoi.name; // Poi名称\nitem.poiid = selPoi.poiid; // PoiID\n// 调用 LonLatToMap 将 经纬度 转换为 P20坐标\nCoord2DDouble coordP20 = OperatorPosture.lonlatToMap(selPoi.poi_loc.lon, selPoi.poi_loc.lat);\nitem.point_x = (int)(coordP20.lon);\nitem.point_y = (int)(coordP20.lat);\nitem.common_name = "家"; // "公司"; 为空时,表示普通收藏点\n// 其他属性赋值\nint tMode =SyncMode.SyncModeLater;\nString result = BehaviorPresenter.getInstance().addFavorite(item, tMode);\n\n//2. 是否是收藏点\nFavoriteBaseItem isItem = new FavoriteBaseItem();\nisItem.name = selPoi.name; // Poi名称\nisItem.poiid = selPoi.poiid; // PoiID\nisItem.point_x = (int)(coordP20.lon);\nisItem.point_y = (int)(coordP20.lat);\nString result = BehaviorPresenter.getInstance().isFavorite(isItem); // 返回 0 表示已收藏\n\n//3. 删除收藏点\nFavoriteBaseItem delItem = new FavoriteBaseItem();\ndelItem.name = "北京新世纪妇儿医院test";\ndelItem.point_x = 221055288;\ndelItem.point_y = 101613545;\nint tMode =SyncMode.SyncModeLater;\nString result = BehaviorPresenter.getInstance().addFavorite(delItem, tMode);\n\n//4. 同步事件回调\npublic class BehaviorPresenter implements IBehaviorServiceObserver \n /**\n * @return void\n * @brief 同步事件回调通知\n * @param[in] eventType 同步SDK回调事件类型\n * @param[in] exCode 同步SDK返回值\n */\n @Override\n public void notify(@SyncEventType.SyncEventType1 int eventType, @SyncRet.SyncRet1 int exCode) {\n // 同步事件处理\n }\n}\n\n
特别说明:这里显示的列表对应数据结构是精简收藏点 SimpleFavoriteItem
int[] com.autonavi.gbl.user.behavior.BehaviorService.getSimpleFavoriteIds()
ArrayList<SimpleFavoriteItem> com.autonavi.gbl.user.behavior.BehaviorService.getSimpleFavoriteList(FavoriteType, boolean)
void com.autonavi.gbl.user.behavior.BehaviorService.getFavoriteListAsync(FavoriteType, boolean)
void com.autonavi.gbl.user.behavior.observer.IBehaviorServiceObserver.notify(FavoriteType, ArrayList<SimpleFavoriteItem>, boolean)
说明:函数详情,请复制函数名称到在线API搜索
BehaviorService mBehaviorService = (BehaviorService) ServiceMgr.getServiceMgrInstance().getBLService(SingleServiceID.BehaviorSingleServiceID);\n//1. 获取精简收藏点列表(同步方式)\nArrayList<SimpleFavoriteItem> favList = mBehaviorService.getSimpleFavoriteList(FavoriteType.FavoriteTypePoi, true);\n/* 显示 精简收藏夹列表 逻辑 */\n\n//2. 获取精简收藏点列表(异步方式)\nmBehaviorService.getFavoriteListAsync(FavoriteType.FavoriteTypePoi, true);\n// 精简收藏夹数据回调\npublic class BehaviorPresenter implements IBehaviorServiceObserver {\n /**\n * 异步获取收藏点回调\n *\n * @param type 收藏点类型\n * @param data 收藏点列表\n * @param sorted 是否排序\n */\n @Override\n public void notify(@FavoriteType.FavoriteType1 int type, ArrayList<SimpleFavoriteItem> data, boolean sorted) {\n // 显示 精简收藏夹列表 逻辑\n }\n}\n\n//3. 获取收藏点个数\nint[] testids = mBehaviorService.getSimpleFavoriteIds();\n\n\n//4. 获取收藏点详细信息\nFavoriteBaseItem getItem = new FavoriteBaseItem();\n// baseItem 赋值\nFavoriteItem item = mBehaviorService.getFavorite(getItem);
PS:重名操作构造 FavoriteItem 参数时除了 custom_name 赋值为 用户输出值,其他字段都要使用从同布库取出时的值,特别时 create_time,经纬度,name 字段
String com.autonavi.gbl.user.behavior.BehaviorService.topFavorite(FavoriteBaseItem, boolean, SyncMode)
String com.autonavi.gbl.user.behavior.BehaviorService.updateFavorite(FavoriteItem, SyncMode)
void com.autonavi.gbl.user.behavior.observer.IBehaviorServiceObserver.notify(SyncEventType, SyncRet)
说明:函数详情,请复制函数名称到在线API搜索
// 获取收藏点操作\nBehaviorService mBehaviorService = (BehaviorService) ServiceMgr.getServiceMgrInstance().getBLService(SingleServiceID.BehaviorSingleServiceID);\nArrayList<SimpleFavoriteItem> favList = mBehaviorService.getSimpleFavoriteList(FavoriteType.FavoriteTypePoi, true);\n\n//1. 收藏点置顶/取消置顶\nFavoriteBaseItem baseItem = new FavoriteBaseItem();\nbaseItem.item_id = favList.get(0).item_id;\nboolean bSetTop = true; // false 取消置顶\nint mode = SyncMode.SyncModeNow; // SyncModeLater 稍后同步\nmBehaviorService.topFavorite(baseItem, bSetTop, mode);\n\n//2. 收藏点重命名\n//2.1 获取收藏点详细数据\nFavoriteBaseItem baseItem = new FavoriteBaseItem();\nbaseItem.item_id = favList.get(0).item_id;\nbaseItem.name = favList.get(0).name;\nbaseItem.point_x = favList.get(0).point_x;\nbaseItem.point_y = favList.get(0).point_y;\nFavoriteItem detailItem = behaviorPresenter.getFavorite(baseItem);\n//2.2 重名\ndetailItem.custom_name = "重命名";\nmBehaviorService.updateFavorite(detailItem, mode);\n\n//3. 同步事件回调\npublic class BehaviorPresenter implements IBehaviorServiceObserver \n /**\n * @return void\n * @brief 同步事件回调通知\n * @param[in] eventType 同步SDK回调事件类型\n * @param[in] exCode 同步SDK返回值\n */\n @Override\n public void notify(@SyncEventType.SyncEventType1 int eventType, @SyncRet.SyncRet1 int exCode) {\n // 同步事件处理\n }\n}