com.baidu.mapapi.search.poi.PoiSearch Java Examples

The following examples show how to use com.baidu.mapapi.search.poi.PoiSearch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocationActivity.java    From imsdk-android with MIT License 6 votes vote down vote up
private void initLocationClient() {
        geoCoder = GeoCoder.newInstance();
        poiSearch = PoiSearch.newInstance();
        poiSearch.setOnGetPoiSearchResultListener(this);
        locationClient = new LocationClient(getApplication());
        LocationClientOption option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        option.setCoorType(CoordinateType.BD09LL);
//        option.setScanSpan(5000);//
        option.setIsNeedAddress(true);
        option.setOpenGps(true);
        option.setLocationNotify(true);
        option.setIsNeedLocationDescribe(true);
        option.setIsNeedLocationPoiList(true);
        option.setIgnoreKillProcess(true);
        option.SetIgnoreCacheException(true);
        option.setEnableSimulateGps(true);
        locationClient.setLocOption(option);
        locationClient.registerLocationListener(this);
        locationClient.start();
    }
 
Example #2
Source File: BusActivity.java    From BaiduMap-TrafficAssistant with MIT License 6 votes vote down vote up
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	requestWindowFeature(Window.FEATURE_NO_TITLE);
	SDKInitializer.initialize(getApplicationContext());
	setContentView(R.layout.activity_bus);
	this.context = this;

	initView();// 省市联动;
	initAdapter();// 省市联动;
	province.setAdapter(arrayAdapterProvince);

	mBaiduMap = ((SupportMapFragment) getSupportFragmentManager()
			.findFragmentById(R.id.bmapView)).getBaiduMap();
	mSearch = PoiSearch.newInstance();
	mBusLineSearch = BusLineSearch.newInstance();
	initListener();
	busLineIDList = new ArrayList<String>();

}
 
Example #3
Source File: MainActivity.java    From MoveMapLocation with Apache License 2.0 5 votes vote down vote up
/**
 * 输入框监听---输入完毕
 *
 * @param s
 */
@Override
public void afterTextChanged(Editable s) {
    if (s.length() == 0 || "".equals(s.toString())) {
        searchPois.setVisibility(View.GONE);
    } else {
        //创建PoiSearch实例
        PoiSearch poiSearch = PoiSearch.newInstance();
        //城市内检索
        PoiCitySearchOption poiCitySearchOption = new PoiCitySearchOption();
        //关键字
        poiCitySearchOption.keyword(s.toString());
        //城市
        poiCitySearchOption.city(city);
        //设置每页容量,默认为每页10条
        poiCitySearchOption.pageCapacity(10);
        //分页编号
        poiCitySearchOption.pageNum(1);
        poiSearch.searchInCity(poiCitySearchOption);
        //设置poi检索监听者
        poiSearch.setOnGetPoiSearchResultListener(new OnGetPoiSearchResultListener() {
            //poi 查询结果回调
            @Override
            public void onGetPoiResult(PoiResult poiResult) {
                List<PoiInfo> poiInfos = poiResult.getAllPoi();
                PoiSearchAdapter poiSearchAdapter = new PoiSearchAdapter(MainActivity.this, poiInfos, locationLatLng);
                searchPois.setVisibility(View.VISIBLE);
                searchPois.setAdapter(poiSearchAdapter);
            }

            //poi 详情查询结果回调
            @Override
            public void onGetPoiDetailResult(PoiDetailResult poiDetailResult) {
            }
        });
    }
}
 
Example #4
Source File: AddressEditDelegate.java    From FastWaiMai with MIT License 4 votes vote down vote up
private void initPoiSearch() {
	// 初始化搜索模块,注册搜索事件监听
	mPoiSearch = PoiSearch.newInstance();
	mPoiSearch.setOnGetPoiSearchResultListener(this);
}
 
Example #5
Source File: LocationDelegate.java    From FastWaiMai with MIT License 4 votes vote down vote up
private void initPoiSearch() {
	// 初始化搜索模块,注册搜索事件监听
	mPoiSearch = PoiSearch.newInstance();
	mPoiSearch.setOnGetPoiSearchResultListener(this);
}
 
Example #6
Source File: MainActivity.java    From BaiDuMapSelectDemo with Apache License 2.0 4 votes vote down vote up
private void initPoiSearch() {
    // 初始化搜索模块,注册搜索事件监听
    mPoiSearch = PoiSearch.newInstance();
    mPoiSearch.setOnGetPoiSearchResultListener(this);
}
 
Example #7
Source File: SetFavoriteMapActivity.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map_of_set_favorite);
    ButterKnife.bind(this);
    mNaviDao = BaiduNaviDao.getInstance();
    mAppConfig = (AppConfig) getApplication();
    ScreenUtil.getInstance().init(this);
    mInflater = LayoutInflater.from(this);
    EventBus.getDefault().register(this);
    //设置模拟状态栏的高度
    ViewGroup.LayoutParams layoutParams = mStatusBar.getLayoutParams();
    layoutParams.height = ScreenUtil.getStatusBarHeight(this);
    mStatusBar.setLayoutParams(layoutParams);

    /* 更新定位 */
    BaiduLocateManager.get().start();
    /* 设置百度地图图层 */
    mAmosfMap.showScaleControl(true);
    mAmosfMap.showZoomControls(false);
    baiduMap = mAmosfMap.getMap();
    baiduMap.setMyLocationEnabled(true);
    /* 初始化百度地址搜索 */
    pSearch = PoiSearch.newInstance();
    pSearch.setOnGetPoiSearchResultListener(this);
    sSearch = SuggestionSearch.newInstance();
    sSearch.setOnGetSuggestionResultListener(this);

    /* 初始化视图 */
    // mAmosfSearchBt.setVisibility(View.GONE);
    mAmosfPoiListBox.setColorSchemeResources(R.color.base_blue);
    mListAdapter = new FavorPointAdapter();
    mAmosfPoiList.setHasFixedSize(true);
    mAmosfPoiList.setLayoutManager(new LinearLayoutManager(this));
    //mAmosfPoiList.addItemDecoration(new SimpleLineDivider(R.color.new_music_bg_color));
    mAmosfPoiList.setAdapter(mListAdapter);
    mAmosfPoiList.post(new Runnable() {
        @Override
        public void run() {
            mAmosfPoiBox.setMaxHeight(findViewById(R.id.amosf_map_box).getMeasuredHeight() - (int) (getResources().getDisplayMetrics().density * 48.0f + 0.5f));
            resetScaleToolPosition();
        }
    });

    /* 设置相关监听器 */
    mAmosfSearchEdit.setSearchListener(searchListener);
    mAmosfSuggestList.setItemClickListener(suggestItemClickListener);
    mAmosfPoiListBox.setOnRefreshListener(this);
    mListAdapter.setOnItemClickListener(listItemClickListener);

    /* 设置地址详情ViewPager参数 */
    mPagerAdapter = new FavorPointPagerAdapter();
    mAmosfPoiDetailPager.setAdapter(mPagerAdapter);
    mAmosfPoiBox.setScaleChangeListener(scaleChangedListener);
    mAmosfPoiDetailPager.addOnPageChangeListener(pageChangeListener);

    mFavAndHisAdapter = new FavoriteAndHistoryAdapter();
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    mNaviFavoriteAndHistory.setLayoutManager(layoutManager);
    mNaviFavoriteAndHistory.setAdapter(mFavAndHisAdapter);
    mAddress = mAppConfig.address;
    if (getIntent() != null) {
        Intent intent = getIntent();
        mode = intent.getIntExtra(MODE, -1);
        favoriteToSetmode = intent.getIntExtra(FAVORITE_TO_SET_MODE, -1);
        receiveAddress = intent.getParcelableExtra("address");
        setInputBoxHint(intent);
    }

    if (receiveAddress != null) {
        receiveAddress.print();
        if (mode == -1) {
            if (receiveAddress.getRemark() != null) {
                if (receiveAddress.getRemark().equals("家")) {
                    mode = SET_HOME;
                } else if (receiveAddress.getRemark().equals("单位")) {
                    mode = SET_COMPANY;
                } else if (receiveAddress.getRemark().equals("出发地")) {
                    mode = SET_START;
                } else if (receiveAddress.getRemark().equals("目的地")) {
                    mode = SET_END;
                }
            }
            mode = SET_FAVORITE;
        }
        setSinglePoiDetail();
        locationReceiveAddress();
    } else {
        if (mode == -1)
            mode = SET_FAVORITE;
        location();
    }
}
 
Example #8
Source File: NaviConfirmPointActivity.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
/**
 * 初始化相关数据
 **/
private void initData() {
    /* 获取poi搜索对象 */
    pSearch = PoiSearch.newInstance();
    pSearch.setOnGetPoiSearchResultListener(this);
    address = mAppConfig.address;
    /* 将坐标系转换成百度坐标系 */
    // g2c_address = address.clone().setBD09LL();
    Intent intent = getIntent();
    if (intent != null) {
        keyword = intent.getStringExtra("data");
        ArrayList<BaiduAddress> addresses = intent.getParcelableArrayListExtra("addresses");
        addMode = intent.getBooleanExtra("add", false);
        if (!TextUtils.isEmpty(keyword)) {
            firstPoiSearch = true;
            /* 在城市内检索,检索结果在poi检索结果回调中显示 */
            pSearch.searchInCity(new PoiCitySearchOption().city(mAppConfig.selectedCityInSearchPoi == null ?
                    address.getCity() : mAppConfig.selectedCityInSearchPoi).keyword(keyword).pageCapacity(PER_PAGE).pageNum(poiPageCode));
        } else if (addresses != null) {
            voiceMode = true;
            /* 设置poi搜索点图层 */
            poiOverlay = new ConfirmCustomPoiOverlay(baiduMap);
            baiduMap.setOnMarkerClickListener(poiOverlay);
            if (poiOverlay instanceof ConfirmCustomPoiOverlay) {
                ((ConfirmCustomPoiOverlay) poiOverlay).setOverlayOptions(addresses);
            }
            //添加PoiOverlay到地图中
            poiOverlay.addToMap();

            aList.clear();
            aList.addAll(addresses);
            setListReverse();
            mListAdapter.notifyDataSetChanged();
            mPagerAdapter.notifyDataSetChanged();
            firstPoiSearch = false;
            mAncpPoiBox.setVisibility(View.VISIBLE);
            mAncpPoiListBox.setAllowDrag(false);
            setPoiPosition();
        }
    }
}
 
Example #9
Source File: FakeWeiBoActivity.java    From AndroidAnimationExercise with Apache License 2.0 4 votes vote down vote up
private void initLocationAndSearch() {

        //location
        mLocationClient = new LocationClient(getApplicationContext());     //声明LocationClient类
        mLocationClient.registerLocationListener(this);    //注册监听函数
        LocationClientOption option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy
        );//可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
        option.setCoorType("bd09ll");//可选,默认gcj02,设置返回的定位结果坐标系
        int span = 1000;
        option.setScanSpan(span);//可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
        option.setIsNeedAddress(true);//可选,设置是否需要地址信息,默认不需要
        option.setOpenGps(true);//可选,默认false,设置是否使用gps
        option.setLocationNotify(true);//可选,默认false,设置是否当GPS有效时按照1S/1次频率输出GPS结果
        option.setIsNeedLocationDescribe(true);//可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
        option.setIsNeedLocationPoiList(true);//可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
        option.setIgnoreKillProcess(false);//可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
        option.SetIgnoreCacheException(false);//可选,默认false,设置是否收集CRASH信息,默认收集
        option.setEnableSimulateGps(false);//可选,默认false,设置是否需要过滤GPS仿真结果,默认需要
        mLocationClient.setLocOption(option);
        //search

        mPoiSearch = PoiSearch.newInstance();
        mPoiSearch.setOnGetPoiSearchResultListener(new MyPoiSearchListener());
        mNearbySearchOption = new PoiNearbySearchOption()
                .radius(5000)
                .pageNum(1)
                .pageCapacity(20)
                .sortType(PoiSortType.distance_from_near_to_far);


        ////////////////
        mGeoCoder = GeoCoder.newInstance();
        mGeoCoder.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() {
            @Override
            public void onGetGeoCodeResult(GeoCodeResult geoCodeResult) {
                Log.e(TAG, "onGetGeoCodeResult: " + geoCodeResult.toString());
            }

            @Override
            public void onGetReverseGeoCodeResult(ReverseGeoCodeResult reverseGeoCodeResult) {
                Log.e(TAG, "onGetReverseGeoCodeResult: " + reverseGeoCodeResult.toString());
            }
        });


    }