多信息窗展示
功能场景
介绍多个点标记和信息窗同时展示的效果,常用于O2O、房产等行业的检索场景中。
Android
iOS
//mapopen-website-wiki.bj.bcebos.com/demos/AndroidVideos/多信息窗展示@android.mp4
1590746640|//mapopen-website-wiki.bj.bcebos.com/demos/newqrcodes/多信息窗展示@2xanidroid.png
扫码体验
使用产品
Android地图SDK|/index.php?title=androidsdk
>
添加文字和信息窗|/index.php?title=androidsdk/guide/render-map/text
下载源码
//mapopen-website-wiki.bj.bcebos.com/demos/BaiduMapSDKExample.zip
核心接口
类
接口
描述
PoiSearch
searchInCity(PoiCitySearchOption option)
城市内检索
PoiSearch
setOnGetPoiSearchResultListener(OnGetPoiSearchResultListener poiResultListener)
设置检索结果回调
PoiCitySearchOption
city(String city)
设置检索城市
PoiCitySearchOption
keyword(String key)
搜索关键字
PoiCitySearchOption
cityLimit(boolean cityLimit)
设置区域数据召回限制,为true时,仅召回city对应区域内数据
MarkerOptions
icon(BitmapDescriptor bitmap)
设置icon
MarkerOptions
extraInfo(Bundle extraInfo)
覆盖物的额外信息
MarkerOptions
position(LatLng latLng)
覆盖物的位置坐标
重点关注
检索完成后,需要调用PoiSearch的destroy()方法,否则会有内存泄露。
核心代码
1.发起检索请求
JAVA
// 发起请求 mPoiSearch.searchInCity((new PoiCitySearchOption()) .city(cityStr) .keyword(keyWordStr) .cityLimit(true) .scope(scope));
复制
深色
复制成功
2.检索结果回调处理
JAVA
@Override public void onGetPoiResult(final PoiResult result) { if (result == null || result.error == SearchResult.ERRORNO.RESULT_NOT_FOUND) { mLoadIndex = 0; mBaiduMap.clear(); Toast.makeText(SearchMarkerDemo.this, "未找到结果", Toast.LENGTH_LONG).show(); return; } if (result.error == SearchResult.ERRORNO.NO_ERROR) { mBaiduMap.clear(); // 添加poi if (mPoiResult == null || mPoiResult.getAllPoi() == null) { return null; } List<OverlayOptions> markerList = new ArrayList<>(); List<InfoWindow> infoWindowList = new ArrayList<>(); int markerSize = 0; for (int i = 0; i < mPoiResult.getAllPoi().size() && markerSize < MAX_POI_SIZE; i++) { if (mPoiResult.getAllPoi().get(i).location == null) { continue; } markerSize++; Bundle bundle = new Bundle(); bundle.putInt("index", i); markerList.add(new MarkerOptions() .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_red)) .extraInfo(bundle) .position(mPoiResult.getAllPoi().get(i).location)); //自定义InfoWindow Button button = new Button(getApplicationContext()); button.setBackgroundResource(R.drawable.bubble); button.setText(mPoiResult.getAllPoi().get(i).address); button.setTextColor(Color.WHITE); button.setPadding(0,0,0,5); button.setTextSize(10); button.setWidth(300); // 创建InfoWindow InfoWindow mInfoWindow = new InfoWindow(BitmapDescriptorFactory.fromView(button), mPoiResult.getAllPoi().get(i).location, -95, null); infoWindowList.add(mInfoWindow); } mBaiduMap.showInfoWindows(infoWindowList); return; } if (result.error == SearchResult.ERRORNO.AMBIGUOUS_KEYWORD) { // 当输入关键字在本市没有找到,但在其他城市找到时,返回包含该关键字信息的城市列表 String strInfo = "在"; for (CityInfo cityInfo: result.getSuggestCityList()) { strInfo += cityInfo.city; strInfo += ","; } strInfo += "找到结果"; } }
复制
深色
复制成功