美文网首页
高德地图搜索区域

高德地图搜索区域

作者: onlyxing | 来源:发表于2017-11-07 13:32 被阅读0次

    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);//强制隐藏键盘

    //请求位置数据

    showProgress(getResources().getString(R.string.loading_text));

    //第一个参数表示地址,第二个参数表示查询城市

    GeocodeQuery geocodeQuery =newGeocodeQuery(searchEditText.getText().toString().trim(),"");

    geocoderSearch.getFromLocationNameAsyn(geocodeQuery);

    //                        poiSearch.searchPOIAsyn();

    return true;

    }

    }

    return false;

    }

    });


    /**

    * 获取地理编码 解析result获取坐标信息

    *@paramgeocodeResult可以在回调中解析result,获取坐标信息。

    *@paramrCode返回结果成功或者失败的响应码。1000为成功,其他为失败(详细信息参见网站开发指南-实用工具-错误码对照表)

    */

    @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();//详细地址

    sDistrict= geocodeAddress.getDistrict();//区县

    LatLonPoint latLonPoint = geocodeAddress.getLatLonPoint();

    if(latLonPoint!=null) {

    sLongitude= latLonPoint.getLongitude() +"";

    sLatitude= latLonPoint.getLatitude() +"";

    aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(

    newLatLng(latLonPoint.getLatitude(), latLonPoint.getLongitude()),16));

    }

    break;

    }

    }

    }

    相关文章

      网友评论

          本文标题:高德地图搜索区域

          本文链接:https://www.haomeiwen.com/subject/qmxjmxtx.html