Search in sources :

Example 6 with PoiItem

use of com.amap.api.services.core.PoiItem in project KL2 by jweihao.

the class AddressAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(MyHolder holder, int position) {
    holder.itemView.setTag(position);
    PoiItem poiItem = mList.get(position);
    if (position == selectPosition) {
        holder.mCheckBox.setChecked(true);
    } else {
        holder.mCheckBox.setChecked(false);
    }
    holder.mTvTitle.setText(poiItem.getTitle());
    holder.mTvMessage.setText(poiItem.getProvinceName() + poiItem.getCityName() + poiItem.getAdName() + poiItem.getSnippet());
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            int position = (Integer) view.getTag();
            setSelectPosition(position);
            if (null != mOnItemClickLisenter) {
                mOnItemClickLisenter.onItemClick(position);
            }
        }
    });
}
Also used : PoiItem(com.amap.api.services.core.PoiItem) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 7 with PoiItem

use of com.amap.api.services.core.PoiItem in project KL2 by jweihao.

the class SearchActivity method initListener.

private void initListener() {
    mOnClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            switch(view.getId()) {
                case R.id.iv_back:
                    finish();
                    break;
                default:
                    break;
            }
        }
    };
    mIvBack.setOnClickListener(mOnClickListener);
    mEtSearch.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (null != editable) {
                if (0 == editable.length()) {
                    // 没有输入则清空搜索记录
                    mList.clear();
                    mSearchAddressAdapter.setList(mList, "");
                } else {
                    if (null != location) {
                        doSearchQuery(editable.toString(), location.getCity(), new LatLonPoint(location.getLatitude(), location.getLongitude()));
                    } else {
                        doSearchQuery(editable.toString(), "", null);
                    }
                }
            }
        }
    });
    mOnItemClickLisenter = new OnItemClickLisenter() {

        @Override
        public void onItemClick(int position) {
            PoiItem poiItem = mList.get(position);
            if (null != poiItem) {
                // 获取信息并回传上一页面
                Intent intent = new Intent();
                intent.putExtra(DatasKey.SEARCH_INFO, poiItem);
                setResult(RESULT_OK, intent);
                finish();
            }
        }
    };
    mSearchAddressAdapter.setOnItemClickLisenter(mOnItemClickLisenter);
    mOnPoiSearchListener = new PoiSearch.OnPoiSearchListener() {

        @Override
        public void onPoiSearched(PoiResult result, int i) {
            if (i == 1000) {
                if (result != null && result.getQuery() != null) {
                    // 搜索poi的结果
                    if (result.getQuery().equals(mQuery)) {
                        // 是否是同一条
                        if (null != mList) {
                            mList.clear();
                        }
                        // 取得第一页的poiitem数据,页数从数字0开始
                        mList.addAll(result.getPois());
                        if (null != mSearchAddressAdapter) {
                            mSearchAddressAdapter.setList(mList, mEtSearch.getText().toString().trim());
                            mRecyclerView.smoothScrollToPosition(0);
                        }
                    }
                }
            }
        }

        @Override
        public void onPoiItemSearched(PoiItem poiItem, int i) {
        }
    };
}
Also used : PoiSearch(com.amap.api.services.poisearch.PoiSearch) PoiResult(com.amap.api.services.poisearch.PoiResult) OnItemClickLisenter(com.jweihao.jdemo.utils.OnItemClickLisenter) Intent(android.content.Intent) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) LatLonPoint(com.amap.api.services.core.LatLonPoint) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) PoiItem(com.amap.api.services.core.PoiItem) LatLonPoint(com.amap.api.services.core.LatLonPoint)

Example 8 with PoiItem

use of com.amap.api.services.core.PoiItem in project KL2 by jweihao.

the class DataConversionUtils method changeToPoiItem.

public static PoiItem changeToPoiItem(AMapLocation data) {
    if (null != data) {
        try {
            String title = data.getDescription();
            if (TextUtils.isEmpty(title)) {
                title = data.getPoiName();
            }
            if (TextUtils.isEmpty(title)) {
                title = data.getStreet();
            }
            if (TextUtils.isEmpty(title)) {
                title = "[位置]";
            }
            PoiItem poiItem = new PoiItem(data.getBuildingId(), new LatLonPoint(data.getLatitude(), data.getLongitude()), title, data.getAddress());
            poiItem.setAdCode(data.getAdCode());
            poiItem.setAdName(data.getDistrict());
            poiItem.setBusinessArea(data.getStreet());
            poiItem.setCityCode(data.getCityCode());
            poiItem.setCityName(data.getCity());
            poiItem.setProvinceName(data.getProvince());
            return poiItem;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }
    return null;
}
Also used : PoiItem(com.amap.api.services.core.PoiItem) LatLonPoint(com.amap.api.services.core.LatLonPoint)

Example 9 with PoiItem

use of com.amap.api.services.core.PoiItem in project KL2 by jweihao.

the class DataConversionUtils method changeToPoiItem.

public static PoiItem changeToPoiItem(RegeocodeResult data) {
    if (null != data) {
        try {
            String title = data.getRegeocodeAddress().getBuilding();
            if (TextUtils.isEmpty(title)) {
                title = data.getRegeocodeAddress().getNeighborhood();
            }
            if (TextUtils.isEmpty(title)) {
                title = data.getRegeocodeAddress().getTownship();
            }
            if (TextUtils.isEmpty(title)) {
                title = "[位置]";
            }
            PoiItem poiItem = new PoiItem(data.getRegeocodeAddress().getBuilding(), data.getRegeocodeQuery().getPoint(), title, data.getRegeocodeAddress().getFormatAddress());
            poiItem.setAdCode(data.getRegeocodeAddress().getAdCode());
            poiItem.setAdName(data.getRegeocodeAddress().getDistrict());
            poiItem.setBusinessArea(data.getRegeocodeAddress().getBusinessAreas().get(0).getName());
            poiItem.setCityCode(data.getRegeocodeAddress().getCityCode());
            poiItem.setCityName(data.getRegeocodeAddress().getCity());
            poiItem.setProvinceName(data.getRegeocodeAddress().getProvince());
            return poiItem;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }
    return null;
}
Also used : PoiItem(com.amap.api.services.core.PoiItem)

Aggregations

PoiItem (com.amap.api.services.core.PoiItem)9 View (android.view.View)5 LatLonPoint (com.amap.api.services.core.LatLonPoint)5 RecyclerView (android.support.v7.widget.RecyclerView)4 Intent (android.content.Intent)3 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 PoiResult (com.amap.api.services.poisearch.PoiResult)2 PoiSearch (com.amap.api.services.poisearch.PoiSearch)2 OnItemClickLisenter (com.jweihao.jdemo.utils.OnItemClickLisenter)2 Bundle (android.os.Bundle)1 Editable (android.text.Editable)1 Spanned (android.text.Spanned)1 TextWatcher (android.text.TextWatcher)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 SearchView (android.widget.SearchView)1 SimpleAdapter (android.widget.SimpleAdapter)1 AMapLocation (com.amap.api.location.AMapLocation)1 AMapLocationListener (com.amap.api.location.AMapLocationListener)1