|
@@ -163,7 +163,7 @@ public class LocationSearchActivity extends BaseActivity {
|
|
|
if (StringUtils.isEmpty(keyWork)) {
|
|
if (StringUtils.isEmpty(keyWork)) {
|
|
|
loadDataByNeer();
|
|
loadDataByNeer();
|
|
|
} else
|
|
} else
|
|
|
- loadDataByCity(StringUtils.isEmpty(keyWork) ? "" : keyWork);
|
|
|
|
|
|
|
+ loadDataByCity();
|
|
|
|
|
|
|
|
break;
|
|
break;
|
|
|
default:
|
|
default:
|
|
@@ -177,27 +177,12 @@ public class LocationSearchActivity extends BaseActivity {
|
|
|
search_edit.addTextChangedListener(new EditChangeListener() {
|
|
search_edit.addTextChangedListener(new EditChangeListener() {
|
|
|
@Override
|
|
@Override
|
|
|
public void afterTextChanged(Editable editable) {
|
|
public void afterTextChanged(Editable editable) {
|
|
|
- if (editable == null) return;
|
|
|
|
|
- String key = editable.toString();
|
|
|
|
|
- List<PoiInfo> chche = new ArrayList<>();
|
|
|
|
|
- if (!ListUtils.isEmpty(listData)) {
|
|
|
|
|
- for (PoiInfo e : listData) {
|
|
|
|
|
- String text = e.city + e.name + e.address;
|
|
|
|
|
- boolean isOK = StringUtils.isInclude(text, key);
|
|
|
|
|
- if (isOK)
|
|
|
|
|
- chche.add(e);
|
|
|
|
|
- }
|
|
|
|
|
- if (ListUtils.isEmpty(chche)) {//如果数据为空,就获取输入的地址对应的数据
|
|
|
|
|
- if (type == 2) {
|
|
|
|
|
- loadDataByCity(key);
|
|
|
|
|
- } else adapter.setListData(null);
|
|
|
|
|
- return;
|
|
|
|
|
- } else {
|
|
|
|
|
- adapter.setListData(chche);
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- loadDataByCity(key);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (editable == null || StringUtils.isEmpty(editable.toString())) return;
|
|
|
|
|
+ keyWork = editable.toString();
|
|
|
|
|
+ if (StringUtils.isEmpty(keyWork))
|
|
|
|
|
+ loadDataByNeer();
|
|
|
|
|
+ else
|
|
|
|
|
+ search();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -205,16 +190,40 @@ public class LocationSearchActivity extends BaseActivity {
|
|
|
@Override
|
|
@Override
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
List<PoiInfo> chche = adapter.getListData();
|
|
List<PoiInfo> chche = adapter.getListData();
|
|
|
- if (ListUtils.isEmpty(chche) || chche.size() <= i) return;
|
|
|
|
|
- endOfActivity(chche.get(i));
|
|
|
|
|
|
|
+ int item = (i - 1) <= 0 ? 0 : (i - 1);
|
|
|
|
|
+ if (ListUtils.isEmpty(chche) || chche.size() <= item) return;
|
|
|
|
|
+ endOfActivity(chche.get(item));
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void search() {
|
|
|
|
|
+ List<PoiInfo> chche = new ArrayList<>();
|
|
|
|
|
+ //1.先搜索本地数据,如果有先筛选出本地符合 2.如果没有,搜索地图
|
|
|
|
|
+ if (!ListUtils.isEmpty(listData)) {
|
|
|
|
|
+ for (PoiInfo e : listData) {
|
|
|
|
|
+ String text = e.city + e.name + e.address;
|
|
|
|
|
+ boolean isOK = StringUtils.isInclude(text, keyWork);
|
|
|
|
|
+ if (isOK)
|
|
|
|
|
+ chche.add(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ListUtils.isEmpty(chche)) {//如果数据为空,就获取输入的地址对应的数据
|
|
|
|
|
+ if (type == 2) {
|
|
|
|
|
+ loadDataByCity();
|
|
|
|
|
+ } else adapter.setListData(null);
|
|
|
|
|
+ return;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ adapter.setListData(chche);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ loadDataByCity();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- private void loadDataByCity(String keyWork) {
|
|
|
|
|
|
|
+ private void loadDataByCity() {
|
|
|
|
|
+ Log.i("gongpengming", "loadDataByCity= " + keyWork);
|
|
|
isChina = true;
|
|
isChina = true;
|
|
|
- BaiduMapUtil.getInstence().searchByInputOnChina(keyWork, pageNum, listener);
|
|
|
|
|
|
|
+ BaiduMapUtil.getInstence().searchByInputOnChina(StringUtils.isEmpty(keyWork) ? "" : keyWork, pageNum, listener);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void loadDataByNeer() {
|
|
private void loadDataByNeer() {
|
|
@@ -238,29 +247,31 @@ public class LocationSearchActivity extends BaseActivity {
|
|
|
listData = null;
|
|
listData = null;
|
|
|
adapter.setListData(listData);
|
|
adapter.setListData(listData);
|
|
|
return;
|
|
return;
|
|
|
|
|
+ }
|
|
|
|
|
+ Log.i("gongpengming", "进来else ");
|
|
|
|
|
+ PoiResult poiResult = (PoiResult) result;
|
|
|
|
|
+ List<PoiInfo> chches = poiResult.getAllPoi();
|
|
|
|
|
+ if (ListUtils.isEmpty(chches)) {
|
|
|
|
|
+ Log.i("gongpengming", "chches==nulll");
|
|
|
|
|
+ Log.i("gongpengming", "isChina=" + isChina);
|
|
|
|
|
+ if (isChina) {
|
|
|
|
|
+ isChina = false;
|
|
|
|
|
+ BaiduMapUtil.getInstence().searchByInput(keyWork, pageNum, listener);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
- PoiResult poiResult = (PoiResult) result;
|
|
|
|
|
- List<PoiInfo> chches = poiResult.getAllPoi();
|
|
|
|
|
- if (ListUtils.isEmpty(chches)) {
|
|
|
|
|
- Log.i("gongpengming", "chches==nulll");
|
|
|
|
|
- if (isChina) {
|
|
|
|
|
- isChina = false;
|
|
|
|
|
- BaiduMapUtil.getInstence().searchByInput(keyWork, pageNum, listener);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- BaiduMapUtil.getInstence().setMapViewPoint(bmapView, chches.get(0).location, true);
|
|
|
|
|
- for (int i = 0; i < chches.size(); i++) {
|
|
|
|
|
- if (StringUtils.isEmpty(chches.get(i).name) || StringUtils.isEmpty(chches.get(i).address)) {
|
|
|
|
|
- chches.remove(i);
|
|
|
|
|
- i--;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Log.i("gongpengming", "chches!!!!!!!!!!!!=nulll ");
|
|
|
|
|
+ BaiduMapUtil.getInstence().setMapViewPoint(bmapView, chches.get(0).location, true);
|
|
|
|
|
+ for (int i = 0; i < chches.size(); i++) {
|
|
|
|
|
+ Log.i("gongpengming", "chches.get(i).name=" + chches.get(i).name);
|
|
|
|
|
+ if (StringUtils.isEmpty(chches.get(i).name) || StringUtils.isEmpty(chches.get(i).address)) {
|
|
|
|
|
+ chches.remove(i);
|
|
|
|
|
+ i--;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- listData = chches;
|
|
|
|
|
- adapter.setListData(listData);
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ listData = chches;
|
|
|
|
|
+ adapter.setListData(listData);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|