android百度地图开发V4.5最新版(8)---POI搜索之周边搜索
来源:互联网 发布:天天特价淘宝网童装 编辑:程序博客网 时间:2024/05/01 01:42
这篇博客介绍周边搜索,全城搜索请看我的博文。
android百度地图开发V4.5最新版(7)---POI搜索之全城搜索
周边搜索主要做以下几件事情:
1:实现位置的定位功能。并且将其marker到地图上。
代码如下:
/** * 定位SDK监听函数 */public MyLocationListenner myListener = new MyLocationListenner();public class MyLocationListenner implements BDLocationListener { @Override public void onReceiveLocation(BDLocation location) { // map view 销毁后不在处理新接收的位置 if (location == null || mMapView == null) { return; } mCurrentLat = location.getLatitude(); mCurrentLon = location.getLongitude(); mCurrentAccracy = location.getRadius(); center = new LatLng(mCurrentLat, mCurrentLon); locData = new MyLocationData.Builder() .accuracy(location.getRadius()) // 此处设置开发者获取到的方向信息,顺时针0-360 .direction(mCurrentDirection).latitude(location.getLatitude()) .longitude(location.getLongitude()).build(); mBaiduMap.setMyLocationData(locData); if (isFirstLoc) { isFirstLoc = false; LatLng ll = new LatLng(location.getLatitude(), location.getLongitude()); MapStatus.Builder builder = new MapStatus.Builder(); builder.target(ll).zoom(18.0f); mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); } } public void onReceivePoi(BDLocation poiLocation) { }}2:设定周边的区域范围是多少:
int radius = 1000;3:绘制定位的overlay到地图上
/** * 对周边检索的范围进行绘制 * @param center * @param radius */public void showNearbyArea( LatLng center, int radius) { BitmapDescriptor centerBitmap = BitmapDescriptorFactory .fromResource(R.drawable.icon_geo); MarkerOptions ooMarker = new MarkerOptions().position(center).icon(centerBitmap); mBaiduMap.addOverlay(ooMarker); OverlayOptions ooCircle = new CircleOptions().fillColor( 0xCCCCCC00 ) .center(center).stroke(new Stroke(5, 0xFFFF00FF )) .radius(radius); mBaiduMap.addOverlay(ooCircle);}4:处理周边搜索的点击响应事件:
/** * 响应周边搜索按钮点击事件 * * @param v */public void searchNearbyProcess(View v) { searchType = 2; PoiNearbySearchOption nearbySearchOption = new PoiNearbySearchOption().keyword(keyWorldsView.getText() .toString()).sortType(PoiSortType.distance_from_near_to_far).location(center) .radius(radius).pageNum(loadIndex); mPoiSearch.searchNearby(nearbySearchOption);}public void goToNextPage(View v) { loadIndex++; searchButtonProcess(null);}第五步:处理搜索结果:
/** * 获取POI搜索结果,包括searchInCity,searchNearby,searchInBound返回的搜索结果 * @param result */public void onGetPoiResult(PoiResult result) { if (result == null || result.error == SearchResult.ERRORNO.RESULT_NOT_FOUND) { Toast.makeText(PoiSearchDemo.this, "未找到结果", Toast.LENGTH_LONG) .show(); return; } if (result.error == SearchResult.ERRORNO.NO_ERROR) { mBaiduMap.clear(); PoiOverlay overlay = new MyPoiOverlay(mBaiduMap); mBaiduMap.setOnMarkerClickListener(overlay); List<PoiInfo> poiInfoList=result.getAllPoi(); for(PoiInfo poiInfo:poiInfoList){ Log.e("搜索信息","地址"+poiInfo.address+"名字"+poiInfo.name+"电话"+poiInfo.phoneNum); } overlay.setData(result); overlay.addToMap(); overlay.zoomToSpan(); switch( searchType ) { case 2: showNearbyArea(center, radius); break; case 3: showBound(searchbound); break; default: break; } return; } if (result.error == SearchResult.ERRORNO.AMBIGUOUS_KEYWORD) { // 当输入关键字在本市没有找到,但在其他城市找到时,返回包含该关键字信息的城市列表 String strInfo = "在"; for (CityInfo cityInfo : result.getSuggestCityList()) { strInfo += cityInfo.city; strInfo += ","; } strInfo += "找到结果"; Toast.makeText(PoiSearchDemo.this, strInfo, Toast.LENGTH_LONG) .show(); }}第六步:在oncreat中添加定位的相关配置:
// 开启定位图层mBaiduMap.setMyLocationEnabled(true);// 定位初始化mLocClient = new LocationClient(this);mLocClient.registerLocationListener(myListener);LocationClientOption option = new LocationClientOption();option.setOpenGps(true); // 打开gpsoption.setCoorType("bd09ll"); // 设置坐标类型option.setScanSpan(1000);mLocClient.setLocOption(option);mLocClient.start();第七步:处理marker的点击事件:
/** * 获取POI详情搜索结果,得到searchPoiDetail返回的搜索结果 * @param result */public void onGetPoiDetailResult(PoiDetailResult result) { if (result.error != SearchResult.ERRORNO.NO_ERROR) { Toast.makeText(PoiSearchDemo.this, "抱歉,未找到结果", Toast.LENGTH_SHORT) .show(); } else { Toast.makeText(PoiSearchDemo.this, result.getName() + ": " + result.getAddress(), Toast.LENGTH_SHORT) .show(); Log.e("结果",result.getName() + ": " + result.getAddress()); tv_test.clearFocus(); tv_test.setText("poi位置信息!!!"+result.getName() + ": " + result.getAddress()); }}以下为效果图
完成代码下载请查看:项目中overlay工具包下载请见:
百度地图工具包overlayutils,百度地图开发必备工具包
百度地图使用详解
阅读全文
0 0
- android百度地图开发V4.5最新版(8)---POI搜索之周边搜索
- android百度地图开发V4.5最新版(7)---POI搜索之全城搜索
- Android百度地图API 之 定位周边搜索POI
- Android 百度地图-实现POI的搜索(搜索周边)
- Android 百度地图-实现POI的搜索(搜索周边)
- Android:百度地图-实现POI的搜索(搜索周边)
- Android 百度地图-实现POI的搜索(搜索周边)
- Android学习笔记之百度地图(POI搜索之周边检索poiSearchNearBy)
- 百度地图API 之 定位周边搜索POI(奉上源代码)+ GoogleMap 详细
- 百度地图-实现POI的搜索(搜索周边)
- Android 百度地图开发 POI搜索
- Android百度地图——搜索服务之周边检索
- 百度地图之周边兴趣点搜索
- Android 百度地图--定位、周边搜索
- 百度地图之POI搜索
- Android 百度地图之全局搜索周边搜索全国搜索城市路线规划(升级版)
- Android学习笔记之百度地图(周边检索poiSearchNearBy跳转页面并输出搜索结果)
- 百度地图的周边搜索
- Linux dd 命令
- idea spring托管hibernate并生成hibernate 实体类映射
- 5分钟认识Simulink仿真
- 数据结构实验之查找五:平方之哈希表
- 分布式系统架构——Mysql数据库实现主从同步
- android百度地图开发V4.5最新版(8)---POI搜索之周边搜索
- Warning Setting property 'source' to 'org.eclipse.jst.jee.server的问题
- 理解伯德图-2/4什么是伯德图
- JS实现复选框的全选和批量删除功能(php后端)
- Thrift 客户端 Python
- 学习网站
- (四)wait()、notify()、notifyAll()方法||wait()与sleep()的区别
- AngualrJS的学习记录(二)
- 解决Android运行过程中出现的NoClassDefFoundError