产品服务
解决方案
文档与支持
定价

文档全面上新

更科技的视觉体验,更高效的页面结构,快前往体验吧!

体验新版
多信息窗展示
功能场景
介绍多个点标记和信息窗同时展示的效果,常用于O2O、房产等行业的检索场景中。
Android
iOS
//mapopen-website-wiki.bj.bcebos.com/demos/AndroidVideos/多信息窗展示@android.mp4
扫码体验
核心接口
接口
描述
searchInCity(PoiCitySearchOption option)
城市内检索
PoiSearch
setOnGetPoiSearchResultListener(OnGetPoiSearchResultListener poiResultListener)
设置检索结果回调
city(String city)
设置检索城市
PoiCitySearchOption
keyword(String key)
搜索关键字
cityLimit(boolean cityLimit)
设置区域数据召回限制,为true时,仅召回city对应区域内数据
icon(BitmapDescriptor bitmap)
设置icon
MarkerOptions
extraInfo(Bundle extraInfo)
覆盖物的额外信息
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 += "找到结果";
    }
}
                
     
                
复制
深色
复制成功
  • 文档根本没法用

  • 文档水平很差

  • 文档水平一般

  • 文档不错

  • 文档写的很好

如发现文档错误,或对此文档有更好的建议,请在下方反馈。问题咨询请前往反馈平台提交工单咨询。

提交反馈

拖动标注工具

添加矩形标注

添加箭头标注

完成

取消