百度地图室内Poi检索

室内Po检索

     界面设计,代码如下: 




    
        

        

            
        
        
        
    
    

其中,circleshape.xml代码如下:




    
    

    
    
    

    
    

界面效果如图:

百度地图室内Poi检索_第1张图片

activity继承这几个接口 

implements  BaiduMap.OnBaseIndoorMapListener, OnGetPoiSearchResultListener

默认定位到北京南站

 LatLng centerpos = new LatLng(39.871281,116.385306); // 北京南站
        MapStatus.Builder builder = new MapStatus.Builder();
        builder.target(centerpos).zoom(19.0f);
        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));

创建检索当前建筑物室内POI检索对象

  mPoiSearch = PoiSearch.newInstance();

设置POI检索监听者

mPoiSearch.setOnGetPoiSearchResultListener(this);

搜索按钮的监听

  indoorsearch_content_et = (EditText) findViewById(R.id.indoorsearch_content_et);
        indoorsearch_search_tv = findViewById(R.id.indoorsearch_search_tv);
        indoorsearch_search_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MapBaseIndoorMapInfo indoorInfo = mBaiduMap.getFocusedBaseIndoorMapInfo();
                if (indoorInfo == null) {
                    Toast.makeText(IndoorSearchActivity.this, "当前无室内图,无法搜索" , Toast.LENGTH_LONG).show();
                    return;
                }
                //设置检索参数
                PoiIndoorOption option = new PoiIndoorOption().poiIndoorBid(
                        indoorInfo.getID()).poiIndoorWd(indoorsearch_content_et.getText().toString());
                //发起检索请求
                mPoiSearch.searchPoiIndoor( option);
                //隐藏软键盘
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

            }
        });
设置监听事件来监听进入和移出室内图

 

  @Override
    public void onBaseIndoorMapMode(boolean b, MapBaseIndoorMapInfo mapBaseIndoorMapInfo) {
        if (b) {
            stripView.setVisibility(View.VISIBLE);
            if (mapBaseIndoorMapInfo == null) {
                return;
            }
            mFloorListAdapter.setmFloorList(mapBaseIndoorMapInfo.getFloors());
            stripView.setStripAdapter(mFloorListAdapter);

        } else {
            stripView.setVisibility(View.GONE);
        }
        mMapBaseIndoorMapInfo = mapBaseIndoorMapInfo;
    }

poi检索结果返回

 @Override
    public void onGetPoiResult(PoiResult poiResult) {

    }

    @Override
    public void onGetPoiDetailResult(PoiDetailResult poiDetailResult) {

    }

    @Override
    public void onGetPoiDetailResult(PoiDetailSearchResult poiDetailSearchResult) {

    }

    @Override
    public void onGetPoiIndoorResult(PoiIndoorResult result) {
        mBaiduMap.clear();
        poiIndoorInfoList.clear();
        if (result == null  || result.error == PoiIndoorResult.ERRORNO.RESULT_NOT_FOUND) {
            Toast.makeText(IndoorSearchActivity.this, "无结果" , Toast.LENGTH_LONG).show();
            return;
        }
        if (result.error == PoiIndoorResult.ERRORNO.NO_ERROR) {
            IndoorPoiOverlay overlay = new MyIndoorPoiOverlay(mBaiduMap);
            poiIndoorInfoList=result.getmArrayPoiInfo();
            indoorsearch_rv.setVisibility(View.VISIBLE);
            indoorsearch_path_bt.setVisibility(View.GONE);
            inDoorSearchAdapter=new InDoorSearchAdapter(poiIndoorInfoList,this,this);
            indoorsearch_rv.setLayoutManager(new LinearLayoutManager(this));
            indoorsearch_rv.setAdapter(inDoorSearchAdapter);
            Log.d("zjccc", poiIndoorInfoList.get(1).address);
            mBaiduMap.setOnMarkerClickListener(overlay);
            //address
            overlay.setData(result);
            overlay.addToMap();
            overlay.zoomToSpan();
        }
    }

注:使用poi检索的时候一定要记得将官方demo中的assets目录下拷贝到自己工程,不然汇报maker's icon can not be null这个错误,

当然你也可以修改设置maker图片的方法,可以用自己的图片

到此,已经可以实现室内poi检索,效果如图:

百度地图室内Poi检索_第2张图片

 

你可能感兴趣的:(百度地图室内Poi检索)