Android 地图搜索商家,检索关键字(高德地图,百度地图),地址搜索
生活随笔
收集整理的這篇文章主要介紹了
Android 地图搜索商家,检索关键字(高德地图,百度地图),地址搜索
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、高德地圖
?
實現效果? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?打印數據
? ? ? ? ? ?
?
實現步驟:
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/
2、配置AK?key和service
jniLibs文件配置
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("東莞市"));} });結果:
?
?
實現demo:https://download.csdn.net/download/meixi_android/12076534
?
?
搜索地址?
?
1、實現接口
implements Inputtips.InputtipsListener2、開始搜索
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;}總結
以上是生活随笔為你收集整理的Android 地图搜索商家,检索关键字(高德地图,百度地图),地址搜索的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Unity shader学习之Grab
- 下一篇: Android 使用ViewPager实