1、高德地图

 

实现效果                                               打印数据

Android 地图搜索商家,检索关键字(高德地图,百度地图),地址搜索-编程知识网           Android 地图搜索商家,检索关键字(高德地图,百度地图),地址搜索-编程知识网

 

实现步骤:

1、首先去高德开放平台注册应用

高德开放平台:https://lbs.amap.com/

 

2、点击  我的应用 ——>设置

注:SHA1获取方法:https://blog.csdn.net/meixi_android/article/details/72547966

 

 3、下载SDK:https://lbs.amap.com/api/android-location-sdk/download/

4、添加配置文件

在工程的“ AndroidManifest.xml ”文件添加key和Service

<meta-data android:name="com.amap.api.v2.apikey"
android:value="afe02836f46f2c42f772ea621027e932" />
<service android:name="com.amap.api.location.APSService"></service>

 

5、搜索关键字代码

    /*** 开始进行poi搜索*/protected void doSearchQuery(String key,boolean ifmore) {if (marker!=null&&!ifmore){
//            marker.remove();aMap.clear(true);}if (ifmore){currentPage ++;}else {currentPage=1;}//不输入城市名称有些地方搜索不到// 第一个参数表示搜索字符串,第二个参数表示poi搜索类型,第三个参数表示poi搜索区域(空字符串代表全国)query = new PoiSearch.Query(key, "", "");
//        query = new PoiSearch.Query(key, key, "");// 设置每页最多返回多少条poiitemquery.setPageSize(5);// 设置查询页码query.setPageNum(currentPage);//构造 PoiSearch 对象,并设置监听poiSearch = new PoiSearch(this, query);poiSearch.setOnPoiSearchListener(this);//调用 PoiSearch 的 searchPOIAsyn() 方法发送请求。poiSearch.searchPOIAsyn();}

实现demo:https://download.csdn.net/download/meixi_android/12003113

 

2、百度地图

1、申请AK key

http://lbsyun.baidu.com/

Android 地图搜索商家,检索关键字(高德地图,百度地图),地址搜索-编程知识网

2、配置AK key和service

Android 地图搜索商家,检索关键字(高德地图,百度地图),地址搜索-编程知识网

jniLibs文件配置

Android 地图搜索商家,检索关键字(高德地图,百度地图),地址搜索-编程知识网

sourceSets {main {jniLibs.srcDirs = ['libs']}
}

 

 

3、调用检索关键字方法

private SuggestionSearch mSuggestionSearch;
editText.addTextChangedListener(new TextWatcher() {@Overridepublic void beforeTextChanged(CharSequence s, int start, int count, int after) {}@Overridepublic void onTextChanged(CharSequence s, int start, int before, int count) {}@Overridepublic void afterTextChanged(Editable s) {mSuggestionSearch.requestSuggestion((new SuggestionSearchOption()).keyword(s.toString()).city("东莞市"));}
});

结果:

 

 Android 地图搜索商家,检索关键字(高德地图,百度地图),地址搜索-编程知识网

实现demo:https://download.csdn.net/download/meixi_android/12076534

 

 

搜索地址 

 

1、实现接口

implements Inputtips.InputtipsListener

2、开始搜索

InputtipsQuery inputquery = new InputtipsQuery(keyWorld, "");
Inputtips inputTips = new Inputtips(SelectAddressActivity.this, inputquery);
inputTips.setInputtipsListener(SelectAddressActivity.this);
inputTips.requestInputtipsAsyn();

3、搜索回调

public static final int REQUEST_SUC = 1000;
@Override
public void onGetInputtips(List<Tip> list, int rCode) {List<SelectAddressBean> data = new ArrayList<>();// 正确返回if (rCode == REQUEST_SUC) {for (int i = 0;i<list.size();i++){SelectAddressBean bean = new SelectAddressBean();LgqLog.e("搜索内容====  "+list.get(i).toString());String allshengshi = list.get(i).getDistrict();String shengs = "";String shis = "";String ares = "";if (allshengshi.contains("黑龙江")) {shengs = "黑龙江省";} else if (allshengshi.contains("内蒙古")) {shengs = "内蒙古自治区";}else if (allshengshi.contains("新疆维吾尔自治区")){shengs ="新疆维吾尔自治区";}else if (allshengshi.contains("西藏自治区")){shengs ="西藏自治区";}else if (allshengshi.contains("广西壮族自治区")){shengs ="广西壮族自治区";} else{if (!TextUtils.isEmpty(allshengshi)) {shengs = allshengshi.substring(0, 3);}}if (!TextUtils.isEmpty(allshengshi)) {String ends = allshengshi.substring(allshengshi.length() - 1, allshengshi.length());if (ends.equals("市")) {shis = getvalue(allshengshi, shengs);} else {if (allshengshi.contains("自治州")) {shis = getvalue(allshengshi, shengs, "州");} else {if (allshengshi.length() > shengs.length()) {if (ends.equals("区")) {shis = getvalue(allshengshi, shengs, "区");if (shis.contains("市")){shis = getvalue(shis,"","市");}} else if (ends.equals("县")) {shis = getvalue(allshengshi, shengs, "县");if (shis.contains("市")){shis = getvalue(shis,"","市");}} else {shis = getvalue(allshengshi, shengs, "市");}}}ares = getvalue(allshengshi, shis);}String namess = list.get(i).getName();String nameendss = namess.substring(namess.length() - 1, namess.length());if (TextUtils.isEmpty(ares)) {if (nameendss.equals("镇") || nameendss.equals("区")) {ares = namess;}}}bean.address = list.get(i).getAddress();bean.province = shengs;bean.city = shis;bean.areas = ares;if (list.get(i).getPoint() != null) {bean.latitude = list.get(i).getPoint().getLatitude();bean.longitude = list.get(i).getPoint().getLongitude();}bean.title = list.get(i).getName();data.add(bean);}mRecyclerView.removeAllViews();mAdapter.setNewData(data);LgqLog.e("搜索内容==33333rrfr==  ");if (mAdapter.getData().size()>0){ShareUtil.sharedPint("youss",1);}else {ShareUtil.sharedPint("youss",0);}} else {Toast.makeText(this, "错误码 :" + rCode, Toast.LENGTH_SHORT).show();}}

4、工具方法

 

    public String getvalue(String alls, String tou, String ends) {String value = "";int startCity = alls.indexOf(tou) + tou.length();int endCity = alls.indexOf(ends, startCity) + 1;
//        int endCity = alls.length();value = alls.substring(startCity, endCity);//获取市return value;}public String getvalue(String alls, String tou) {String value = "";int startCity = alls.indexOf(tou) + tou.length();
//        int endCity = alls.indexOf("ends", startCity);int endCity = alls.length();value = alls.substring(startCity, endCity);//获取市return value;}