基于指定输入文本的百度地图poi城市检索的使用(思路最重要)
来源:互联网 发布:如何开发聊天软件 编辑:程序博客网 时间:2024/05/18 17:41
(转载请注明出处哦)具体的百度地图权限和apikey配置以及基础地图的配置不叙述,百度地图定位可以看这个链接的http://blog.csdn.net/heweigzf/article/details/51084358,先来看一波搜索需要的基本布局layout
<AutoCompleteTextView android:id="@+id/autosearchresult" android:background="@null" android:hint="@string/please_input_addr" android:layout_width="match_parent" android:layout_height="@dimen/y30" android:completionThreshold="2"android:background="@drawable/edittext_shap" android:singleLine="true"/><ListView android:id="@+id/poimsglist" android:divider="@color/grey" android:dividerHeight="1px" android:layout_width="match_parent" android:layout_height="match_parent"/>
AutoCompleteTextView可以换成EditTextView,都是可以的,既然是城市poi检索,就会有需要的城市名,可以是定位得到的也可以是传值过来的,这里我就以Intent传值的形式了,先初始化城市检索核心类
/** * 城市内搜索 */ private void citySearch(int page,String keyword,int pageCapacity) { Intent intent=getIntent(); if(intent!=null){ String city=intent.getStringExtra("city"); if(city!=null){ mPoiSearch=PoiSearch.newInstance(); mPoiSearch.setOnGetPoiSearchResultListener(this); // 监听检索结果回调 // 设置检索参数 PoiCitySearchOption citySearchOption = new PoiCitySearchOption(); citySearchOption.city(city);// 城市 citySearchOption.keyword(keyword);// 关键字 citySearchOption.pageCapacity(pageCapacity);// 默认每页10条 citySearchOption.pageNum(page);// 分页编号 // 发起检索请求 mPoiSearch.searchInCity(citySearchOption); } } }接下来就是运用以上的方法了,可以明显的看出来我们是通过输入框来自动检索,需要的给AutoCompleteTextView设置输入监听
@Overridepublic void beforeTextChanged(CharSequence s, int start, int count,int after) {}@Overridepublic void onTextChanged(CharSequence s, int start, int before, int count) {}// 输入完成后自动进行检索调用以上citySearch方法@Overridepublic void afterTextChanged(Editable s) {String searchdialog=s.toString();if(searchdialog.length()>1){citySearch(0, searchdialog, 20);}}
检索成功后,以下为OnGetPoiSearchResultListener回调的检索结果,getAllPoi()包含所有的检索结果
@Overridepublic void onGetPoiDetailResult(PoiDetailResult arg0) {//获取Place详情页检索结果}@Overridepublic void onGetPoiResult(PoiResult arg0) {//获取POI检索结果 if(arg0.error!=SearchResult.ERRORNO.NO_ERROR){//BaseApp.getInstance().showToast("检索fail");}else {if(addrs!=null){addrs.clear();}if(mlLatLngs!=null){mlLatLngs.clear();}if(names!=null){names.clear();}if(arg0.getAllPoi()!=null&&arg0.getAllPoi().size()>0){List<PoiInfo> mPoiInfos=arg0.getAllPoi();for (int i = 0; i < mPoiInfos.size(); i++) {names.add(mPoiInfos.get(i).name);addrs.add(mPoiInfos.get(i).address);mlLatLngs.add(mPoiInfos.get(i).location);<span style="white-space:pre"></span>//对需要的信息设置适配器,如果想在其他界面用,可以自己创建回调接口<span style="white-space:pre"></span>mSearchListAdapter=new SearchListAdapter(addrs, names, BaseApp.getInstance());poiresultlist.setAdapter(mSearchListAdapter);}}}}
最后很重要的一步,要记得销毁poisearch对象,避免可能会报空指针异常
@Overridepublic void onBackPressed() {super.onBackPressed();if(mPoiSearch!=null){mPoiSearch.destroy();}}@Overridepublic void onDestroy() {super.onDestroy();if(mPoiSearch!=null){mPoiSearch.destroy();}}觉得好的可以收藏哦,觉得有问题的可以提出来哦
1 0
- 基于指定输入文本的百度地图poi城市检索的使用(思路最重要)
- 百度地图的POI搜索中:是否可以只输入一个关键词,不输入城市,
- Android学习笔记之百度地图(POI搜索之城市poi检索poiSearchInCity)
- Android学习笔记之百度地图(POI搜索之城市poi检索poiSearchInCity)
- 使用百度地图API进行城市检索
- iOS百度地图城市POI搜索(基于百度地图SDK2.3.0)
- 百度地图POI检索
- iOS百度地图poi检索(基于百度地图2.3.0SDK开发)
- BaiduMap初体验(五) 使用百度地图的POI和云检索
- Python爬虫(二)--利用百度地图API批量获取城市所有的POI点
- 百度地图开发(二)POI检索
- 百度地图----检索功能的使用
- iOS百度地图POI的使用
- 百度地图基于某个城市景点的查找截取列表
- 百度地图POI检索实例
- 百度地图Android POI检索
- 百度地图的城市定位
- iOS-Andriod百度地图仿百度外卖-饿了么-选择我的地址-POI检索/
- Hadoop入门的五个进程的理解(二)
- 根据一个笔试题引出的思考
- Python nltk载入自己的中文语料库的两种方法 for Windows7
- CodeForces 552C:Vanya and Scales【技巧】
- hal层
- 基于指定输入文本的百度地图poi城市检索的使用(思路最重要)
- 51Nod-1069-Nim游戏
- 一个数组变换的算法问题-关于前端的分页功能排序(点击/热门)功能
- hdu2955 Robberies --01背包
- 简单C++ log 类
- 设计模式是什么?
- 认识——数据库存储过程和游标
- mysql开启慢查询日志和新增日志--linux
- JSP