Search in sources :

Example 1 with CameraPosition

use of com.amap.api.maps.model.CameraPosition in project ride-read-android by Ride-Read.

the class MapFragment method initView.

@Override
public void initView() {
    mHandler = new WeakHandler();
    mAMap = mMapView.getMap();
    //实例化UiSettings类对象
    mUiSettings = mAMap.getUiSettings();
    mUiSettings.setZoomControlsEnabled(false);
    mUiSettings.setCompassEnabled(true);
    mCurZoom = 18;
    mAMap.moveCamera(CameraUpdateFactory.zoomBy(mCurZoom));
    // 设置定位监听
    mAMap.setLocationSource(this);
    // 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
    mAMap.setMyLocationEnabled(true);
    //        mUiSettings.setMyLocationButtonEnabled(true); //显示默认的定位按钮
    // 设置定位的类型为定位模式,有定位、跟随或地图根据面向方向旋转几种
    //初始化定位蓝点样式类
    MyLocationStyle myLocationStyle = new MyLocationStyle();
    //        myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);
    //        myLocationStyle.(2000);
    myLocationStyle.radiusFillColor(getResources().getColor(R.color.blue_a20));
    //连续定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。(1秒1次定位)如果不设置myLocationType,默认也会执行此种模式。
    myLocationStyle.strokeColor(getResources().getColor(R.color.blue_a20));
    mAMap.setMyLocationStyle(myLocationStyle);
    mAMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
    AMapLocationUtils.init();
    mEdtSearch.setOnEditorActionListener((v, actionId, event) -> {
        if (KeyEvent.KEYCODE_ENTER == event.getKeyCode()) {
            searchKeyWord();
            KeyboardUtils.hideSoftInput(getActivity());
            return true;
        }
        return false;
    });
    mEdtSearch.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence keyword, int start, int count, int after) {
            if (TextUtils.isEmpty(keyword)) {
                mImgClear.setVisibility(View.GONE);
            } else {
                mImgClear.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    mAMap.setOnMarkerClickListener(marker -> {
        Moment moment = (Moment) marker.getObject();
        if (null != moment) {
            Bundle bundle = new Bundle();
            int isFollow = moment.getUser().getIsFollowed();
            bundle.putInt(MomentDetailActivity.SELECTED_MOMENT_MID, moment.getMid());
            bundle.putInt(MomentDetailActivity.USER_TYPE, 0);
            getBaseActivity().gotoActivity(MomentDetailActivity.class, bundle);
        }
        return false;
    });
    mAMap.setOnCameraChangeListener(new AMap.OnCameraChangeListener() {

        @Override
        public void onCameraChange(CameraPosition cameraPosition) {
        }

        @Override
        public void onCameraChangeFinish(CameraPosition cameraPosition) {
            int tempZoom = (int) cameraPosition.zoom;
            if (mIsShowNearby && mCurZoom != tempZoom) {
                mCurZoom = tempZoom;
                loadMapMoments(mCurZoom);
            }
        }
    });
}
Also used : WeakHandler(com.badoo.mobile.util.WeakHandler) CameraPosition(com.amap.api.maps.model.CameraPosition) MyLocationStyle(com.amap.api.maps.model.MyLocationStyle) MapMoment(com.rideread.rideread.data.result.MapMoment) Moment(com.rideread.rideread.data.result.Moment) AMap(com.amap.api.maps.AMap) Bundle(android.os.Bundle) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) LatLonPoint(com.amap.api.services.core.LatLonPoint) Point(android.graphics.Point)

Example 2 with CameraPosition

use of com.amap.api.maps.model.CameraPosition in project JustAndroid by chinaltz.

the class MapActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activitty_nearbypark);
    ButterKnife.bind(this);
    isFirstInitMap = true;
    mContext = this;
    navTitle.setText("地图相关导航");
    String[] titles = { "新街口", "夫子庙", "百家湖", "河西万达" };
    hotAreaList = new ArrayList();
    LatLng xinjiekouLatlng = new LatLng(32.0414637353, 118.7851165312);
    LatLng fuzimiaoLatlng = new LatLng(32.0206226446, 118.7889921341);
    LatLng baijiahuLatlng = new LatLng(31.9319650736, 118.8212252856);
    LatLng hexiLatlng = new LatLng(32.0328683928, 118.7360117294);
    hotAreaList.add(xinjiekouLatlng);
    hotAreaList.add(fuzimiaoLatlng);
    hotAreaList.add(baijiahuLatlng);
    hotAreaList.add(hexiLatlng);
    hListViewAdapter = new HorizontalListViewAdapter(getApplicationContext(), titles);
    horizontalListView.setAdapter(hListViewAdapter);
    horizontalListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            hListViewAdapter.setSelectIndex(position);
            aMap.animateCamera(CameraUpdateFactory.newLatLngZoom((LatLng) hotAreaList.get(position), 14));
            addMarkersToMap((LatLng) hotAreaList.get(position), position + 1);
        }
    });
    // 此方法必须重写
    mapView.onCreate(savedInstanceState);
    if (aMap == null) {
        aMap = mapView.getMap();
        CameraUpdate mCameraUpdate = CameraUpdateFactory.zoomTo(14);
        aMap.moveCamera(mCameraUpdate);
        //            aMap.getUiSettings().setMyLocationButtonEnabled(false);// 设置默认定位按钮是否显示
        //            aMap.getUiSettings().setCompassEnabled(false);
        aMap.getUiSettings().setScaleControlsEnabled(true);
        didLocation();
        aMap.setOnMarkerClickListener(new AMap.OnMarkerClickListener() {

            @Override
            public boolean onMarkerClick(Marker marker) {
                int index = Integer.parseInt(marker.getSnippet());
                popupInfo(paopaoView, index);
                return true;
            }
        });
        aMap.setOnMapClickListener(new AMap.OnMapClickListener() {

            @Override
            public void onMapClick(LatLng latLng) {
                paopaoView.setVisibility(View.INVISIBLE);
            }
        });
        aMap.setOnCameraChangeListener(new AMap.OnCameraChangeListener() {

            @Override
            public void onCameraChange(CameraPosition cameraPosition) {
            }

            @Override
            public void onCameraChangeFinish(CameraPosition cameraPosition) {
                LatLng target = cameraPosition.target;
                if (isFirstInitMap) {
                    isFirstInitMap = false;
                } else {
                //                        getNearParkList(target.longitude + "", target.latitude + "");
                }
            }
        });
    }
    searchEditText.setFocusable(false);
    searchEditText.setOnClickListener(new View.OnClickListener() {

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

        @Override
        public void onClick(View v) {
            didLocation();
        }
    });
}
Also used : AMap(com.amap.api.maps.AMap) ArrayList(java.util.ArrayList) Marker(com.amap.api.maps.model.Marker) MapView(com.amap.api.maps.MapView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AdapterView(android.widget.AdapterView) HorizontalListView(com.ningcui.mylibrary.viewLib.HorizontalListView) TextView(android.widget.TextView) CameraPosition(com.amap.api.maps.model.CameraPosition) AdapterView(android.widget.AdapterView) LatLng(com.amap.api.maps.model.LatLng) NaviLatLng(com.amap.api.navi.model.NaviLatLng) HorizontalListViewAdapter(com.litingzhe.justandroid.ui.mapView.adapter.HorizontalListViewAdapter) CameraUpdate(com.amap.api.maps.CameraUpdate)

Aggregations

AMap (com.amap.api.maps.AMap)2 CameraPosition (com.amap.api.maps.model.CameraPosition)2 Point (android.graphics.Point)1 Bundle (android.os.Bundle)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 CameraUpdate (com.amap.api.maps.CameraUpdate)1 MapView (com.amap.api.maps.MapView)1 LatLng (com.amap.api.maps.model.LatLng)1 Marker (com.amap.api.maps.model.Marker)1 MyLocationStyle (com.amap.api.maps.model.MyLocationStyle)1 NaviLatLng (com.amap.api.navi.model.NaviLatLng)1 LatLonPoint (com.amap.api.services.core.LatLonPoint)1 WeakHandler (com.badoo.mobile.util.WeakHandler)1 HorizontalListViewAdapter (com.litingzhe.justandroid.ui.mapView.adapter.HorizontalListViewAdapter)1