Android高德地图自定义放大缩小控件

高德地图sdk默认的地图放大缩小控件由于大小不太合适,因此我们又自己定义了一个
Android高德地图自定义放大缩小控件_第1张图片

1.在布局文件中定义两个ImageView

                       "@+id/iv_zoom_large"
                        android:clickable="true"
                        android:src="@drawable/icon_zoom_large"
                        android:layout_width="35dp"
                        android:layout_height="35dp"
                        android:scaleType="fitXY"

                        />

                    "@+id/iv_zoom_small"
                        android:clickable="true"
                        android:src="@drawable/icon_zoom_small"
                        android:layout_width="35dp"
                        android:layout_height="35dp"

                        android:scaleType="fitXY"

2.处理放大缩小的点击事件

 @OnClick({R.id.iv_zoom_small, R.id.rl_scale_loc_compass})
    public void onClick(View view) {
        Intent intent;
         CameraPosition cameraPosition;
         float mapZoom;
         LatLng mapTarget;
        switch (view.getId()) {

            case R.id.iv_zoom_large:
                cameraPosition = aMap.getCameraPosition();
                mapZoom = cameraPosition.zoom;
                mapTarget = cameraPosition.target;
                Log.d(TAG, "onClick: large"+cameraPosition.target.latitude+":"+mapZoom);
                scaleLargeMap(mapTarget, ++mapZoom);
                break;
            case R.id.iv_zoom_small:

                 cameraPosition = aMap.getCameraPosition();
                 mapZoom = cameraPosition.zoom;
                 mapTarget = cameraPosition.target;
                Log.d(TAG, "onClick: small"+cameraPosition.target.latitude+":"+mapZoom);

                scaleLargeMap(mapTarget,--mapZoom);
                break;
            case R.id.rl_scale_loc_compass:
                break;
        }
    }

  public void scaleLargeMap(LatLng nowLocation,float scaleValue) {
        aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(nowLocation, scaleValue));
//        aMap.moveCamera();
    }

你可能感兴趣的:(Android高德地图自定义放大缩小控件)