public void onGetPoiResult(PoiResult result) { if (result == null || result.error == SearchResult.ERRORNO.RESULT_NOT_FOUND) { Toast.makeText(PoiSearchDemo.this, "未找到结果", Toast.LENGTH_LONG).show(); return; } if (result.error == SearchResult.ERRORNO.NO_ERROR) { status = address_; poiResultAdapter2.setDate(result.getAllPoi()); poi_lv.setAdapter(poiResultAdapter2); mBaiduMap.clear(); PoiOverlay overlay = new MyPoiOverlay(mBaiduMap); mBaiduMap.setOnMarkerClickListener(overlay); overlay.setData(result); overlay.addToMap(); overlay.zoomToSpan(); Log.d("baidu_wjx", "find"); return; } if (result.error == SearchResult.ERRORNO.AMBIGUOUS_KEYWORD) { status = city_; poiResultAdapter.setDate(result.getSuggestCityList()); poi_lv.setAdapter(poiResultAdapter); // 当输入关键字在本市没有找到,但在其他城市找到时,返回包含该关键字信息的城市列表 String strInfo = "在"; for (CityInfo cityInfo : result.getSuggestCityList()) { strInfo += cityInfo.city; strInfo += ","; } strInfo += "找到结果"; Toast.makeText(PoiSearchDemo.this, strInfo, Toast.LENGTH_LONG).show(); Log.d("baidu_wjx", strInfo); } }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (status == city_) { CityInfo poiInfo = (CityInfo) poiResultAdapter.getItem(position); city = poiInfo.city; Log.d("baidu_wjx", "you city:" + city); } else { PoiInfo poiInfo = (PoiInfo) poiResultAdapter2.getItem(position); Intent i = new Intent(); i.putExtra("address", poiInfo.city + poiInfo.address + poiInfo.name); setResult(RESULT_OK, i); finish(); Log.d("baidu_wjx", "you selected:" + poiInfo.city + poiInfo.address + poiInfo.name); } }