Search in sources :

Example 1 with PoiItem

use of com.amap.api.services.core.PoiItem in project YourEyes by SevenLJY.

the class PoiSearchActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_poisearch);
    sv_destination = (SearchView) findViewById(R.id.sv_destination);
    lv_result = (ListView) findViewById(R.id.lv_result);
    poiItems = new ArrayList<PoiItem>();
    listItems = new ArrayList<Map<String, String>>();
    //对搜索框的设置
    //设置不自动缩小为图标
    sv_destination.setIconifiedByDefault(false);
    //显示搜索按钮
    sv_destination.setSubmitButtonEnabled(true);
    longitude = 0;
    latitude = 0;
    latitudeStatus = 0;
    city = "";
    //初始化定位
    initLocation();
    startLocation();
    //搜索框搜索监听
    sv_destination.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String s) {
            //点击搜索时触发,将搜索结果展示在ListView中
            for (int num = 0; num < listItems.size(); num++) {
                listItems.get(num).clear();
            }
            listItems.clear();
            if (city.length() != 0) {
                //city值仍为""时无意义,搜索所得位置不在本城市,该处处理为不予显示
                query = new PoiSearch.Query(s, "", city);
                //设置每页展示20个结果
                query.setPageSize(10);
                //设置查询页码
                query.setPageNum(0);
                poiSearch = new PoiSearch(PoiSearchActivity.this, query);
                //设置周边搜索的中心点以及半径,以定位的当前位置为中心点
                poiSearch.setBound(new PoiSearch.SearchBound(new LatLonPoint(latitude, longitude), 3000));
                poiSearch.setOnPoiSearchListener(new PoiSearch.OnPoiSearchListener() {

                    @Override
                    public void onPoiSearched(PoiResult poiResult, int i) {
                        //搜索结果在列表中显示
                        if (i == 1000 && poiResult != null) {
                            poiItems = poiResult.getPois();
                            for (PoiItem item : poiItems) {
                                listItem = new HashMap<String, String>();
                                listItem.put("title", item.toString());
                                listItem.put("content", item.getCityName() + item.getAdName() + item.getSnippet());
                                listItem.put("latitude", Double.toString(item.getLatLonPoint().getLatitude()));
                                listItem.put("longitude", Double.toString(item.getLatLonPoint().getLongitude()));
                                listItems.add(listItem);
                                item.toString();
                            }
                            adapter = new SimpleAdapter(PoiSearchActivity.this, listItems, R.layout.array_poiitems, new String[] { "title", "content" }, new int[] { R.id.tv_title, R.id.tv_content });
                            lv_result.setAdapter(adapter);
                        } else {
                            ToastUtil.show(PoiSearchActivity.this, "无搜索结果 请检查关键字");
                        }
                    }

                    @Override
                    public void onPoiItemSearched(PoiItem poiItem, int i) {
                    //搜索结果回调,暂时不需使用
                    }
                });
                poiSearch.searchPOIAsyn();
            } else {
                ToastUtil.show(PoiSearchActivity.this, "正在获取定位信息  请稍候");
            }
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            //搜索框文字改变时触发,暂不做优化
            return false;
        }
    });
    /**
         * 为列表项单击事件添加监听
         * 单击相应列表项时跳转到导航界面并将目的地传至导航界面
         * */
    lv_result.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Bundle data = new Bundle();
            data.putDouble("latitude", Double.parseDouble(listItems.get(i).get("latitude")));
            data.putDouble("longitude", Double.parseDouble(listItems.get(i).get("longitude")));
            data.putDouble("myLatitude", latitude);
            data.putDouble("myLongitude", longitude);
            if (latitude == 0) {
                ToastUtil.show(PoiSearchActivity.this, "您的定位信息出错,请检查是否打开了GPS");
            } else {
                Intent intent = new Intent(PoiSearchActivity.this, BasicWalkNaviActivity.class);
                intent.putExtras(data);
                startActivity(intent);
            }
        }
    });
}
Also used : PoiResult(com.amap.api.services.poisearch.PoiResult) PoiItem(com.amap.api.services.core.PoiItem) LatLonPoint(com.amap.api.services.core.LatLonPoint) PoiSearch(com.amap.api.services.poisearch.PoiSearch) Bundle(android.os.Bundle) SimpleAdapter(android.widget.SimpleAdapter) Intent(android.content.Intent) SearchView(android.widget.SearchView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) LatLonPoint(com.amap.api.services.core.LatLonPoint) SearchView(android.widget.SearchView) AdapterView(android.widget.AdapterView) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with PoiItem

use of com.amap.api.services.core.PoiItem in project LivingInCampus by DulCoder.

the class PoiAroundSearchActivity method onMarkerClick.

/**
 * marker的点击事件
 * @param marker
 * @return
 */
@Override
public boolean onMarkerClick(Marker marker) {
    if (marker.getObject() != null) {
        whetherToShowDetailInfo(true);
        try {
            PoiItem mCurrentPoi = (PoiItem) marker.getObject();
            if (mLastMarker == null) {
                mLastMarker = marker;
            } else {
                // 将之前被点击的marker置为原来的状态
                resetLastMarker();
                mLastMarker = marker;
            }
            detailMarker = marker;
            detailMarker.setIcon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.poi_marker_pressed)));
            setPoiItemDisplayContent(mCurrentPoi);
        } catch (Exception e) {
        // TODO: handle exception
        }
    } else {
        whetherToShowDetailInfo(false);
        resetLastMarker();
    }
    return true;
}
Also used : PoiItem(com.amap.api.services.core.PoiItem)

Example 3 with PoiItem

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

the class SearchAddressAdapter 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);
    }
    String name = poiItem.getTitle();
    if (TextUtils.isEmpty(userInput)) {
        holder.mTvTitle.setText(name);
    } else {
        try {
            if (name != null && name.contains(userInput)) {
                // 如果搜索出来的文字跟输入文字有重叠,则改变重叠文字的颜色
                int index = name.indexOf(userInput);
                int len = userInput.length();
                Spanned temp = Html.fromHtml(name.substring(0, index) + "<font color=#19ad19>" + name.substring(index, index + len) + "</font>" + name.substring(index + len, name.length()));
                holder.mTvTitle.setText(temp);
            } else {
                holder.mTvTitle.setText(name);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            holder.mTvTitle.setText(name);
        }
    }
    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) Spanned(android.text.Spanned) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 4 with PoiItem

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

the class GaoDeActivity method initListener.

private void initListener() {
    // 监测地图画面的移动
    mAMap.setOnCameraChangeListener(new AMap.OnCameraChangeListener() {

        @Override
        public void onCameraChangeFinish(CameraPosition cameraPosition) {
            if (null != location && null != cameraPosition && isSearchData) {
                mIvLocation.setImageResource(R.mipmap.location_gps_black);
                zoom = cameraPosition.zoom;
                if (null != mSelectByListMarker) {
                    mSelectByListMarker.setVisible(false);
                }
                getAddressInfoByLatLong(cameraPosition.target.latitude, cameraPosition.target.longitude);
                startTransAnimator();
            // doSearchQuery(true, "", location.getCity(), new LatLonPoint(cameraPosition.target.latitude, cameraPosition.target.longitude));
            }
            if (!isSearchData) {
                isSearchData = true;
            }
        }

        @Override
        public void onCameraChange(CameraPosition cameraPosition) {
        }
    });
    // 设置触摸地图监听器
    mAMap.setOnMapClickListener(new AMap.OnMapClickListener() {

        @Override
        public void onMapClick(LatLng latLng) {
            isSearchData = true;
        }
    });
    // Poi搜索监听器
    mOnPoiSearchListener = new onPoiSearchLintener();
    // 逆地址搜索监听器
    mOnGeocodeSearchListener = new GeocodeSearch.OnGeocodeSearchListener() {

        @Override
        public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
            if (i == 1000) {
                if (regeocodeResult != null) {
                    userSelectPoiItem = DataConversionUtils.changeToPoiItem(regeocodeResult);
                    if (null != mList) {
                        mList.clear();
                    }
                    mList.addAll(regeocodeResult.getRegeocodeAddress().getPois());
                    if (null != userSelectPoiItem) {
                        mList.add(0, userSelectPoiItem);
                    }
                    mAddressAdapter.setList(mList);
                    mRecyclerView.smoothScrollToPosition(0);
                }
            }
        }

        @Override
        public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
        }
    };
    // gps定位监听器
    mAMapLocationListener = new AMapLocationListener() {

        @Override
        public void onLocationChanged(AMapLocation loc) {
            try {
                if (null != loc) {
                    stopLocation();
                    if (loc.getErrorCode() == 0) {
                        // 可在其中解析amapLocation获取相应内容。
                        location = loc;
                        SPUtils.putString(GaoDeActivity.this, DatasKey.LOCATION_INFO, gson.toJson(location));
                        doWhenLocationSucess();
                    } else {
                        // 定位失败时,可通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息,详见错误码表。
                        Log.e("AmapError", "location Error, ErrCode:" + loc.getErrorCode() + ", errInfo:" + loc.getErrorInfo());
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    };
    // recycleview列表监听器
    mAddressAdapter.setOnItemClickLisenter(new OnItemClickLisenter() {

        @Override
        public void onItemClick(int position) {
            try {
                isSearchData = false;
                mIvLocation.setImageResource(R.mipmap.location_gps_black);
                moveMapCamera(mList.get(position).getLatLonPoint().getLatitude(), mList.get(position).getLatLonPoint().getLongitude());
                refleshSelectByListMark(mList.get(position).getLatLonPoint().getLatitude(), mList.get(position).getLatLonPoint().getLongitude());
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });
    // 控件点击监听器
    mOnClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            switch(view.getId()) {
                case R.id.iv_back:
                    finish();
                    break;
                case R.id.iv_search:
                    // Toast.makeText(MainActivity.this, "搜索", Toast.LENGTH_SHORT).show();
                    startActivityForResult(new Intent(GaoDeActivity.this, SearchActivity.class), SEARCHREQUESTCODE);
                    break;
                case R.id.iv_location:
                    // Toast.makeText(MainActivity.this, "定位", Toast.LENGTH_SHORT).show();
                    mIvLocation.setImageResource(R.mipmap.location_gps_green);
                    if (null != mSelectByListMarker) {
                        mSelectByListMarker.setVisible(false);
                    }
                    if (null == location) {
                        startLocation();
                    } else {
                        doWhenLocationSucess();
                    }
                    break;
                case R.id.bt_send:
                    if (null != mList && 0 < mList.size() && null != mAddressAdapter) {
                        int position = mAddressAdapter.getSelectPositon();
                        if (position < 0) {
                            position = 0;
                        } else if (position > mList.size()) {
                            position = mList.size();
                        }
                        PoiItem poiItem = mList.get(position);
                        Toast.makeText(GaoDeActivity.this, "发送:" + poiItem.getTitle() + "  " + poiItem.getSnippet() + "  " + "纬度:" + poiItem.getLatLonPoint().getLatitude() + "  " + "经度:" + poiItem.getLatLonPoint().getLongitude(), Toast.LENGTH_SHORT).show();
                    }
                    break;
                default:
                    break;
            }
        }
    };
    mIvBack.setOnClickListener(mOnClickListener);
    mIvSearch.setOnClickListener(mOnClickListener);
    mIvLocation.setOnClickListener(mOnClickListener);
    mBtSend.setOnClickListener(mOnClickListener);
}
Also used : AMapLocation(com.amap.api.location.AMapLocation) AMap(com.amap.api.maps2d.AMap) OnItemClickLisenter(com.jweihao.jdemo.utils.OnItemClickLisenter) AMapLocationListener(com.amap.api.location.AMapLocationListener) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) MapView(com.amap.api.maps2d.MapView) LatLonPoint(com.amap.api.services.core.LatLonPoint) CameraPosition(com.amap.api.maps2d.model.CameraPosition) GeocodeSearch(com.amap.api.services.geocoder.GeocodeSearch) RegeocodeResult(com.amap.api.services.geocoder.RegeocodeResult) PoiItem(com.amap.api.services.core.PoiItem) LatLng(com.amap.api.maps2d.model.LatLng) GeocodeResult(com.amap.api.services.geocoder.GeocodeResult)

Example 5 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)

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