GeocodeQuery
implements:
LocationSource,?AMapLocationListener, GeocodeSearch.OnGeocodeSearchListener, PoiSearch.OnPoiSearchListener
private EditText searchEditText;
private GeocodeSearch geocoderSearch;
private PoiSearch poiSearch;
private PoiSearch.Query poiQuery;
searchEditText.setOnEditorActionListener(newTextView.OnEditorActionListener() {
@Override
public booleanonEditorAction(TextView v,intactionId, KeyEvent event) {
if(!TextUtils.isEmpty(searchEditText.getText().toString())) {
if(actionId == EditorInfo.IME_ACTION_SEARCH
|| (event !=null&& event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
if((searchEditText.getText() +"").trim().length() ==0) {
return true;
}
inm.hideSoftInputFromWindow(searchEditText.getWindowToken(),0);//強(qiáng)制隱藏鍵盤
//請求位置數(shù)據(jù)
showProgress(getResources().getString(R.string.loading_text));
//第一個(gè)參數(shù)表示地址寺董,第二個(gè)參數(shù)表示查詢城市
GeocodeQuery geocodeQuery =newGeocodeQuery(searchEditText.getText().toString().trim(),"");
geocoderSearch.getFromLocationNameAsyn(geocodeQuery);
//? ? ? ? ? ? ? ? ? ? ? ? poiSearch.searchPOIAsyn();
return true;
}
}
return false;
}
});
/**
* 獲取地理編碼 解析result獲取坐標(biāo)信息
*@paramgeocodeResult可以在回調(diào)中解析result绑改,獲取坐標(biāo)信息。
*@paramrCode返回結(jié)果成功或者失敗的響應(yīng)碼舍悯。1000為成功,其他為失敗(詳細(xì)信息參見網(wǎng)站開發(fā)指南-實(shí)用工具-錯(cuò)誤碼對照表)
*/
@Override
public voidonGeocodeSearched(GeocodeResult geocodeResult,intrCode) {
hideProgress();
if(rCode !=1000){
showToast("獲取地址失敗");
return;
}
List list = geocodeResult.getGeocodeAddressList();
if(list!=null&& list.size()>0){
//? ? ? ? ? ? showBottomSheetDialog(list);
String str =newGson().toJson(list);
LogUtils.log(str);
for(GeocodeAddress geocodeAddress:list){
sAddressArea= geocodeAddress.getProvince()+" "+geocodeAddress.getCity()+" "+geocodeAddress.getDistrict();
sAddressDetail= geocodeAddress.getFormatAddress();//詳細(xì)地址
sDistrict= geocodeAddress.getDistrict();//區(qū)縣
LatLonPoint latLonPoint = geocodeAddress.getLatLonPoint();
if(latLonPoint!=null) {
sLongitude= latLonPoint.getLongitude() +"";
sLatitude= latLonPoint.getLatitude() +"";
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
newLatLng(latLonPoint.getLatitude(), latLonPoint.getLongitude()),16));
}
break;
}
}
}