我做的毕设是关于android的公交查询。然后搜索站点的时候,使用关键字,
返回的所有兴趣点 type 不是枚举常量中的任意一个 而是为空。原因是什么??
代码如下:
public class ExpActivity extends AppCompatActivity {
Button exp_btn;
EditText exp_edit;
ListView exp_list;
public int totalpages=0;
public BusLineSearch busLineSearch;
public PoiSearch poiSearch;
public PoiDetailSearchOption poiDetailSearchOption;
public String busLindId;
public String edit;
public BusLineSearchOption option;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.activity_exp);
exp_btn=(Button)findViewById(R.id.exp_btn);
exp_edit=(EditText)findViewById(R.id.exp_edit);
exp_list=(ListView)findViewById(R.id.exp_list);
poiSearch=PoiSearch.newInstance();
poiSearch.setOnGetPoiSearchResultListener(poiListener);
// busLineSearch=BusLineSearch.newInstance();
// busLineSearch.setOnGetBusLineSearchResultListener(listener);
ButtonClick();
}
public void ButtonClick(){
exp_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edit=exp_edit.getText().toString();
poiSearch.searchInCity((new PoiCitySearchOption().city("厦门").keyword(edit))); //城市范围内搜索 关键字, 但搜索返回的结果 地点好像没有带有类型。
}
});
}
OnGetPoiSearchResultListener poiListener =new OnGetPoiSearchResultListener() {
@Override
public void onGetPoiResult(PoiResult poiResult) {
List<String>data=new ArrayList<String>();
if (poiResult==null || poiResult.error== SearchResult.ERRORNO.RESULT_NOT_FOUND)
{
Toast.makeText(ExpActivity.this, "未找到结果", Toast.LENGTH_SHORT).show();
return;
}
if (poiResult.error==SearchResult.ERRORNO.NO_ERROR){
for (int i=0;i<poiResult.getAllPoi().size();i++){
PoiInfo poiInfo=poiResult.getAllPoi().get(i);
data.add(poiInfo.name);
if (poiInfo.type==PoiInfo.POITYPE.BUS_STATION){
Toast.makeText(ExpActivity.this,"搜索到公交线路了!!", Toast.LENGTH_LONG).show();
busLindId=poiInfo.uid;
}
if (poiInfo.type==null){
Toast.makeText(ExpActivity.this,"为何没有类型",Toast.LENGTH_LONG).show(); //执行程序时 显示的是这一提示。
}
}
}
exp_list.setAdapter(new ArrayAdapter<String>(ExpActivity.this,android.R.layout.simple_list_item_1,data));
}