Search in sources :

Example 11 with LatLonPoint

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

the class GaoDeActivity method getAddressInfoByLatLong.

/**
 * 通过经纬度获取当前地址详细信息,逆地址编码
 *
 * @param latitude
 * @param longitude
 */
private void getAddressInfoByLatLong(double latitude, double longitude) {
    GeocodeSearch geocodeSearch = new GeocodeSearch(this);
    /*
        point - 要进行逆地理编码的地理坐标点。
        radius - 查找范围。默认值为1000,取值范围1-3000,单位米。
        latLonType - 输入参数坐标类型。包含GPS坐标和高德坐标。 可以参考RegeocodeQuery.setLatLonType(String)
        */
    RegeocodeQuery query = new RegeocodeQuery(new LatLonPoint(latitude, longitude), 3000, GeocodeSearch.AMAP);
    geocodeSearch.getFromLocationAsyn(query);
    geocodeSearch.setOnGeocodeSearchListener(mOnGeocodeSearchListener);
}
Also used : GeocodeSearch(com.amap.api.services.geocoder.GeocodeSearch) RegeocodeQuery(com.amap.api.services.geocoder.RegeocodeQuery) LatLonPoint(com.amap.api.services.core.LatLonPoint)

Example 12 with LatLonPoint

use of com.amap.api.services.core.LatLonPoint 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 13 with LatLonPoint

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

the class MyLocationActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mylocation);
    longitude = -1;
    btn_getLocation = (Button) findViewById(R.id.btn_getLocation);
    tv_location = (TextView) findViewById(R.id.tv_location);
    et_destinationName = (EditText) findViewById(R.id.et_destinationName);
    btn_toNavi = (Button) findViewById(R.id.btn_toNavi);
    tv_destination = (TextView) findViewById(R.id.tv_destination);
    dest_longitude = 0;
    dest_latitude = 0;
    //初始化定位和地址解析
    initLocation();
    search = new GeocodeSearch(this);
    search.setOnGeocodeSearchListener(new GeocodeSearch.OnGeocodeSearchListener() {

        @Override
        public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
        // RegeocodeAddress addr = regeocodeResult.getRegeocodeAddress();
        }

        @Override
        public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
            GeocodeAddress addr = geocodeResult.getGeocodeAddressList().get(0);
            LatLonPoint latlng = addr.getLatLonPoint();
            dest_longitude = latlng.getLongitude();
            dest_latitude = latlng.getLatitude();
            String temp = "";
            temp += "经度:" + dest_longitude + "\n";
            temp += "纬度:" + dest_latitude + "\n";
            tv_destination.setText(temp);
        }
    });
    btn_getLocation.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            startLocation();
        }
    });
    btn_toNavi.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            destinationName = et_destinationName.getText().toString().trim();
            if (destinationName.equals("")) {
                ToastUtil.show(MyLocationActivity.this, "请输入有效地址");
            } else {
                if (city != null) {
                    GeocodeQuery query = new GeocodeQuery(destinationName, city);
                    search.getFromLocationNameAsyn(query);
                }
            }
        }
    });
}
Also used : GeocodeAddress(com.amap.api.services.geocoder.GeocodeAddress) GeocodeSearch(com.amap.api.services.geocoder.GeocodeSearch) RegeocodeResult(com.amap.api.services.geocoder.RegeocodeResult) GeocodeResult(com.amap.api.services.geocoder.GeocodeResult) LatLonPoint(com.amap.api.services.core.LatLonPoint) TextView(android.widget.TextView) View(android.view.View) LatLonPoint(com.amap.api.services.core.LatLonPoint) GeocodeQuery(com.amap.api.services.geocoder.GeocodeQuery)

Example 14 with LatLonPoint

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

the class GaoDeActivity method doWhenLocationSucess.

/**
 * 当定位成功需要做的事情
 */
private void doWhenLocationSucess() {
    isSearchData = false;
    userSelectPoiItem = DataConversionUtils.changeToPoiItem(location);
    doSearchQuery(true, "", location.getCity(), new LatLonPoint(location.getLatitude(), location.getLongitude()));
    moveMapCamera(location.getLatitude(), location.getLongitude());
    refleshLocationMark(location.getLatitude(), location.getLongitude());
}
Also used : LatLonPoint(com.amap.api.services.core.LatLonPoint)

Example 15 with LatLonPoint

use of com.amap.api.services.core.LatLonPoint 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)

Aggregations

LatLonPoint (com.amap.api.services.core.LatLonPoint)24 LatLng (com.amap.api.maps.model.LatLng)5 PoiItem (com.amap.api.services.core.PoiItem)5 View (android.view.View)4 ArrayList (java.util.ArrayList)4 Intent (android.content.Intent)3 GeocodeSearch (com.amap.api.services.geocoder.GeocodeSearch)3 RecyclerView (android.support.v7.widget.RecyclerView)2 ImageView (android.widget.ImageView)2 PolylineOptions (com.amap.api.maps.model.PolylineOptions)2 LatLng (com.amap.api.maps2d.model.LatLng)2 GeocodeResult (com.amap.api.services.geocoder.GeocodeResult)2 RegeocodeResult (com.amap.api.services.geocoder.RegeocodeResult)2 PoiResult (com.amap.api.services.poisearch.PoiResult)2 PoiSearch (com.amap.api.services.poisearch.PoiSearch)2 TMC (com.amap.api.services.route.TMC)2 OnItemClickLisenter (com.jweihao.jdemo.utils.OnItemClickLisenter)2 Bundle (android.os.Bundle)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1