Search in sources :

Example 1 with CameraPosition

use of com.amap.api.maps2d.model.CameraPosition in project summer-android by cn-cerc.

the class ClockInActivity method onLocationChanged.

@Override
public void onLocationChanged(AMapLocation aMapLocation) {
    if (mListener != null && aMapLocation != null) {
        if (aMapLocation != null && aMapLocation.getErrorCode() == 0) {
            if (isFirstLoc) {
                CameraPosition LUJIAZUI = new CameraPosition.Builder().target(new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude())).zoom(17).bearing(0).tilt(45).build();
                aMap.animateCamera(CameraUpdateFactory.newCameraPosition(LUJIAZUI));
                isFirstLoc = false;
            }
            // 显示系统小蓝点
            mListener.onLocationChanged(aMapLocation);
            NowLocation = aMapLocation;
            myLaLn = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude());
            Log.i("Location", aMapLocation.getLatitude() + "::::" + aMapLocation.getLongitude());
            if (markerOption == null) {
                String address = NowLocation.getProvince() + NowLocation.getCity() + NowLocation.getDistrict() + NowLocation.getStreet() + NowLocation.getStreetNum() + NowLocation.getAoiName();
                text_address.setText(address);
                latLngSign = myLaLn;
                markerOption = new MarkerOptions().icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)).position(new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude())).draggable(true);
            }
        } else {
            String errText = "定位失败," + aMapLocation.getErrorCode() + ": " + aMapLocation.getErrorInfo();
            Log.e("AmapErr", errText);
            ActivityCompat.requestPermissions(ClockInActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION }, 0x67);
        }
    }
}
Also used : CameraPosition(com.amap.api.maps2d.model.CameraPosition) MarkerOptions(com.amap.api.maps2d.model.MarkerOptions) LatLng(com.amap.api.maps2d.model.LatLng)

Example 2 with CameraPosition

use of com.amap.api.maps2d.model.CameraPosition in project summer-android by cn-cerc.

the class ClockInActivity method setUpMap.

private void setUpMap() {
    aMap.setMapType(3);
    // 设置定位监听
    aMap.setLocationSource(this);
    // 设置默认定位按钮是否显示
    aMap.getUiSettings().setMyLocationButtonEnabled(true);
    // 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
    aMap.setMyLocationEnabled(true);
    // 设置定位的类型为定位模式 ,可以由定位、跟随或地图根据面向方向旋转几种
    aMap.setMyLocationType(1);
    CameraPosition LUJIAZUI = new CameraPosition.Builder().target(new LatLng(22.579652, 113.861323)).zoom(17).bearing(0).tilt(45).build();
    aMap.animateCamera(CameraUpdateFactory.newCameraPosition(LUJIAZUI));
    setupLocationStyle();
    aMap.setOnMapClickListener(this);
    aMap.moveCamera(CameraUpdateFactory.zoomTo(18));
    geocoderSearch = new GeocodeSearch(this);
    geocoderSearch.setOnGeocodeSearchListener(this);
    progDialog = new ProgressDialog(this);
}
Also used : CameraPosition(com.amap.api.maps2d.model.CameraPosition) GeocodeSearch(com.amap.api.services.geocoder.GeocodeSearch) LatLng(com.amap.api.maps2d.model.LatLng) ProgressDialog(android.app.ProgressDialog)

Example 3 with CameraPosition

use of com.amap.api.maps2d.model.CameraPosition 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 4 with CameraPosition

use of com.amap.api.maps2d.model.CameraPosition in project summer-android by cn-cerc.

the class ClockInActivity method changeToAmapView.

private void changeToAmapView(Bundle savedInstanceState) {
    if (myLaLn == null) {
        mAmapView = new MapView(this, new AMapOptions().camera(new CameraPosition(new LatLng(114.025, 22.540412), 16, 0, 0)));
    } else {
        mAmapView = new MapView(this, new AMapOptions().camera(new CameraPosition(new LatLng(myLaLn.latitude, myLaLn.longitude), 16, 0, 0)));
    }
    mAmapView.onCreate(savedInstanceState);
    mAmapView.onResume();
    mContainerLayout.addView(mAmapView);
    if (aMap == null) {
        aMap = mAmapView.getMap();
        setUpMap();
        setupLocationStyle();
    }
}
Also used : CameraPosition(com.amap.api.maps2d.model.CameraPosition) MapView(com.amap.api.maps2d.MapView) AMapOptions(com.amap.api.maps2d.AMapOptions) LatLng(com.amap.api.maps2d.model.LatLng)

Aggregations

CameraPosition (com.amap.api.maps2d.model.CameraPosition)4 LatLng (com.amap.api.maps2d.model.LatLng)4 MapView (com.amap.api.maps2d.MapView)2 GeocodeSearch (com.amap.api.services.geocoder.GeocodeSearch)2 ProgressDialog (android.app.ProgressDialog)1 Intent (android.content.Intent)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 AMapLocation (com.amap.api.location.AMapLocation)1 AMapLocationListener (com.amap.api.location.AMapLocationListener)1 AMap (com.amap.api.maps2d.AMap)1 AMapOptions (com.amap.api.maps2d.AMapOptions)1 MarkerOptions (com.amap.api.maps2d.model.MarkerOptions)1 LatLonPoint (com.amap.api.services.core.LatLonPoint)1 PoiItem (com.amap.api.services.core.PoiItem)1 GeocodeResult (com.amap.api.services.geocoder.GeocodeResult)1 RegeocodeResult (com.amap.api.services.geocoder.RegeocodeResult)1 OnItemClickLisenter (com.jweihao.jdemo.utils.OnItemClickLisenter)1