1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 安卓百度地图之地址关键字搜索

安卓百度地图之地址关键字搜索

时间:2019-12-19 08:58:13

相关推荐

安卓百度地图之地址关键字搜索

步骤一:初始化以及配置

dependencies {compile 'com.baidu.lbsyun:BaiduMapSDK_Search:7.4.0'}

SuggestionSearch mSuggestionSearch = SuggestionSearch.newInstance();

步骤二:内容的搜索

mSuggestionSearch.requestSuggestion((new SuggestionSearchOption()).keyword(editable.toString()) // 关键字.city("西安市")); // 城市mSuggestionSearch.setOnGetSuggestionResultListener(new OnGetSuggestionResultListener() {@Overridepublic void onGetSuggestionResult(SuggestionResult suggestionResult) {mTipListStart.clear();ChoiceAddressModel choiceAddressModel ;for(int i=0;i<suggestionResult.getAllSuggestions().size();i++){Log.i("pony_log", "address:" + suggestionResult.getAllSuggestions().get(i).getKey());if (suggestionResult.getAllSuggestions().get(i).getKey().length()>0) {choiceAddressModel = new ChoiceAddressModel();choiceAddressModel.setAddress(suggestionResult.getAllSuggestions().get(i).getKey());choiceAddressModel.setZuobiao(suggestionResult.getAllSuggestions().get(i).getPt());choiceAddressModel.setZoom(suggestionResult.getAllSuggestions().get(i).getDistrict());mTipListStart.add(choiceAddressModel);}}Log.i("pony_log", "address:" + mTipListStart.size());BusPoiAdapter busPoiAdapter = new BusPoiAdapter(SearchActivity.this, mTipListStart);mListMessage.setAdapter(busPoiAdapter);}});

全部代码:

package com.meal;import android.content.Context;import android.content.Intent;import android.os.Bundle;import android.text.Editable;import android.text.TextUtils;import android.text.TextWatcher;import android.util.Log;import android.view.View;import android.view.inputmethod.InputMethodManager;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.EditText;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.ListView;import android.widget.TextView;import com.baidu.mapapi.search.sug.OnGetSuggestionResultListener;import com.baidu.mapapi.search.sug.SuggestionResult;import com.baidu.mapapi.search.sug.SuggestionSearch;import com.baidu.mapapi.search.sug.SuggestionSearchOption;import com.pony.adapter.BusPoiAdapter;import com.pony.base.BaseActivity;import com.pony.model.ChoiceAddressModel;import com.pony.observer.ChoiceObservable;import com.pony.util.ToastUtil;import java.util.ArrayList;import java.util.List;public class SearchActivity extends BaseActivity {// 标题private TextView mTvTitle;// 返回private ImageView mIvBack;private TextView mIvStu;private ListView mListMessage;private LinearLayout mllNomessage;List<ChoiceAddressModel> mTipListStart = new ArrayList<ChoiceAddressModel>();private EditText metName;private SuggestionSearch mSuggestionSearch = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_im_recommend);initWidget();initData();}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.mIvBack:finish();break;case R.id.mtvSearch:if (TextUtils.isEmpty(metName.getText().toString())) {ToastUtil.ShowCentre(this, "请输入搜索信息");return;}hideSoft(this, metName);break;}}/** 隐藏软键盘*/public void hideSoft(Context context, EditText edittext) {try {if (edittext != null && context != null) {InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);}} catch (Exception e) {e.printStackTrace();}}@Overridepublic void initWidget() {metName = (EditText) findViewById(R.id.metName);mIvStu = (TextView) findViewById(R.id.mIvStu);mIvStu.setText("添加");mIvStu.setVisibility(View.GONE);mllNomessage = (LinearLayout) findViewById(R.id.mllNomessage);mListMessage = (ListView) findViewById(R.id.mListMessage);mIvBack = (ImageView) findViewById(R.id.mIvBack);mTvTitle = (TextView) findViewById(R.id.mTvTitle);mTvTitle.setText("地址信息搜索");mIvBack.setVisibility(View.VISIBLE);mIvBack.setOnClickListener(this);mIvStu.setOnClickListener(this);metName.addTextChangedListener(new TextWatcher() {@Overridepublic void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}@Overridepublic void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}@Overridepublic void afterTextChanged(Editable editable) {if(editable.toString().length()>0){mSuggestionSearch.requestSuggestion((new SuggestionSearchOption()).keyword(editable.toString()) // 关键字.city("西安市")); // 城市mSuggestionSearch.setOnGetSuggestionResultListener(new OnGetSuggestionResultListener() {@Overridepublic void onGetSuggestionResult(SuggestionResult suggestionResult) {mTipListStart.clear();ChoiceAddressModel choiceAddressModel ;for(int i=0;i<suggestionResult.getAllSuggestions().size();i++){Log.i("pony_log", "address:" + suggestionResult.getAllSuggestions().get(i).getKey());if (suggestionResult.getAllSuggestions().get(i).getKey().length()>0) {choiceAddressModel = new ChoiceAddressModel();choiceAddressModel.setAddress(suggestionResult.getAllSuggestions().get(i).getKey());choiceAddressModel.setZuobiao(suggestionResult.getAllSuggestions().get(i).getPt());choiceAddressModel.setZoom(suggestionResult.getAllSuggestions().get(i).getDistrict());mTipListStart.add(choiceAddressModel);}}Log.i("pony_log", "address:" + mTipListStart.size());BusPoiAdapter busPoiAdapter = new BusPoiAdapter(SearchActivity.this, mTipListStart);mListMessage.setAdapter(busPoiAdapter);}});}}});}@Overridepublic void initData() {// 初始化建议搜索模块,注册建议搜索事件监听mSuggestionSearch = SuggestionSearch.newInstance();mListMessage.setOnItemClickListener(new OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {////Log.i("pony_log","address111111111:"+mTipListStart.get(pos).getAddress());//Intent intent = new Intent();////把需要返回的数据存放在intent//intent.putExtra("zuobiao", mTipListStart.get(pos));//intent.putExtra("address", mTipListStart.get(pos).getAddress()+"");////设置返回数据//setResult(RESULT_OK, intent);if(SearchActivity.this.getIntent().getStringExtra("type").equals("1")){mTipListStart.get(pos).setType(1);}else{mTipListStart.get(pos).setType(2);}ChoiceObservable.getInstance().notifyStepChange(mTipListStart.get(pos));finish();}});}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。