Search in sources :

Example 1 with AMap

use of com.amap.api.maps.AMap in project YourEyes by SevenLJY.

the class MapActivity method init.

/**
     * 初始化AMap对象
     * */
private void init() {
    if (aMap == null) {
        //获取地图对象
        aMap = mapView.getMap();
        //显示定位层并可以显示定位
        aMap.setMyLocationEnabled(true);
        aMap.setOnMyLocationChangeListener(new AMap.OnMyLocationChangeListener() {

            @Override
            public void onMyLocationChange(Location location) {
            //位置变化时不做任何事
            }
        });
        //对地图显示UI进行初始化设置
        //初始化设置
        uiSettings = aMap.getUiSettings();
        //指南针可见
        uiSettings.setCompassEnabled(false);
        //以下三行为logo位置
        uiSettings.setLogoBottomMargin(5);
        uiSettings.setLogoLeftMargin(5);
        uiSettings.setLogoPosition(AMapOptions.LOGO_POSITION_BOTTOM_LEFT);
        //定位按钮可见
        uiSettings.setMyLocationButtonEnabled(true);
        //设置可手势旋转
        uiSettings.setRotateGesturesEnabled(true);
        //比例尺控件可见
        uiSettings.setScaleControlsEnabled(true);
        //手势滑动不可用
        uiSettings.setScrollGesturesEnabled(true);
        //倾斜手势不可用
        uiSettings.setTiltGesturesEnabled(false);
        //缩放按钮可见
        uiSettings.setZoomControlsEnabled(true);
        //手势缩放可用
        uiSettings.setZoomGesturesEnabled(true);
        //缩放按钮位置
        uiSettings.setZoomPosition(AMapOptions.ZOOM_POSITION_RIGHT_BUTTOM);
        //创建一个设置放大级别的CameraUpdate
        CameraUpdate cuZoom = CameraUpdateFactory.zoomTo(18);
        //设置地图默认放大级别并实施
        aMap.moveCamera(cuZoom);
        //定位蓝点设置
        //初始化定位蓝点样式类
        myLocationStyle = new MyLocationStyle();
        //只定位一次
        myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_SHOW);
        //设置定位蓝点的Style
        aMap.setMyLocationStyle(myLocationStyle);
    }
}
Also used : MyLocationStyle(com.amap.api.maps.model.MyLocationStyle) AMap(com.amap.api.maps.AMap) CameraUpdate(com.amap.api.maps.CameraUpdate) AMapLocation(com.amap.api.location.AMapLocation) Location(android.location.Location)

Example 2 with AMap

use of com.amap.api.maps.AMap 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 CameraUpdate (com.amap.api.maps.CameraUpdate)2 Location (android.location.Location)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 AMapLocation (com.amap.api.location.AMapLocation)1 MapView (com.amap.api.maps.MapView)1 CameraPosition (com.amap.api.maps.model.CameraPosition)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 HorizontalListViewAdapter (com.litingzhe.justandroid.ui.mapView.adapter.HorizontalListViewAdapter)1 HorizontalListView (com.ningcui.mylibrary.viewLib.HorizontalListView)1 ArrayList (java.util.ArrayList)1