2019独角兽企业重金招聘Python工程师标准>>>
POI检索其实很简单,分为周边检索,区域检索,城市内检索
实例化对象,设置参数,监听回调
search = PoiSearch.newInstance();
search.setOnGetPoiSearchResultListener(poiListener);
//发起周边检索请求
search.searchNearby((new PoiNearbySearchOption()
.radius(5000)) //设置周边检索范围
.location(BaiduLocation.getCInstance(getApplicationContext()).getLatLng()) //城市
.keyword(text) //关键字
.pageNum(10) //分页编号
.pageCapacity(15)); //默认每页10条
OnGetPoiSearchResultListener poiListener = new OnGetPoiSearchResultListener(){
public void onGetPoiResult(PoiResult result){
//获取POI检索结果
if (null == result) {// 没有找到检索结果
MyToastUtils.show(MainActivity.this, "未查询到结果");
return;
}
//清除覆盖物
map.clear();
final List allPoi = result.getAllPoi();
if (null != allPoi) {
String[] str = new String[allPoi.size()];
for (int i = 0; i < allPoi.size(); i++) {
str[i] = allPoi.get(i).name;
}
ArrayAdapter adapter = new ArrayAdapter(MainActivity.this,R.layout.item_showpoi_list,str);
dialog_showpoi_list.setAdapter(adapter);
poiDialog.show();
dialog_showpoi_list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> arg0, View view,
int position, long arg3) {
LatLng item_latlng = allPoi.get(position).location;
//屏幕中心移动到这里
setMarker(item_latlng,"");
//放置数据到覆盖物上
Bundle bundle = new Bundle();
MarkerInfo info = new MarkerInfo();
info.setTitle(allPoi.get(position).name);
info.setAddress(allPoi.get(position).address);
info.setPhoneNum(allPoi.get(position).phoneNum);
bundle.putSerializable("info", info);
marker.setExtraInfo(bundle);
uid = allPoi.get(position).uid;
}
});
}else{
MyToastUtils.show(MainActivity.this, "未查到资源");
}
}
public void onGetPoiDetailResult(PoiDetailResult result){
//获取Place详情页检索结果
}
@Override
public void onGetPoiIndoorResult(PoiIndoorResult result) {
}
};