高德地图Android,绘制自定义定位蓝点、marker、面
16lz
2021-01-23
public class LineUpActivity extends BaseActivity implements LocationSource { @BindView(R.id.line_up_map) MapView mapView; private AMap aMap; private UiSettings uiSettings; private AMapLocationClient aMapLocationClient; private AMapLocationClientOption aMapLocationClientOption; private OnLocationChangedListener locationChangedListener; private AppDialog dialog; @Override protected int getLayout() { return R.layout.activity_line_up; } @Override protected void initView() { initMap(); } private void initMap() { if (aMap == null) { aMap = mapView.getMap(); } uiSettings = aMap.getUiSettings(); uiSettings.setZoomControlsEnabled(false); aMap.setMyLocationEnabled(true); aMapLocationClient = new AMapLocationClient(this); aMapLocationClient.setLocationListener(aMapLocation -> { Log.d("map","myLocation:lat="+aMapLocation.getLatitude()+",lon="+aMapLocation.getLongitude()+",zoomLevel="+aMap.getMaxZoomLevel()); if (locationChangedListener == null || aMapLocation == null) { return; } if (aMapLocation.getErrorCode() == AMapLocation.LOCATION_SUCCESS) { locationChangedListener.onLocationChanged(aMapLocation); } }); aMapLocationClientOption = new AMapLocationClientOption(); aMapLocationClientOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); aMapLocationClientOption.setInterval(5000); aMapLocationClient.setLocationOption(aMapLocationClientOption); //显示定位标记 MyLocationStyle myLocationStyle = new MyLocationStyle(); Bitmap iconBitmap = BitmapFactory.decodeResource(getResources(),R.mipmap.ic_my_location); myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromBitmap(iconBitmap)); //透明定位精度圆圈 myLocationStyle.strokeWidth(0); myLocationStyle.strokeColor(Color.TRANSPARENT); myLocationStyle.radiusFillColor(Color.TRANSPARENT); //定位间隔 myLocationStyle.interval(5000); //连续定位、蓝点不会移动到地图中心点,定位点依照设备方向旋转,并且蓝点会跟随设备移动。 myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER); aMap.setMyLocationStyle(myLocationStyle); aMapLocationClient.startLocation(); //位置 LatLng latLng = new LatLng(38.438,106.215); //地图view中心点和缩放级别设置 aMap.moveCamera(CameraUpdateFactory.changeLatLng(latLng)); aMap.moveCamera(CameraUpdateFactory.zoomTo(aMap.getMaxZoomLevel()-3)); //添加marker MarkerOptions markerOptions = new MarkerOptions(); markerOptions.position(latLng); Bitmap companyIcon = BitmapFactory.decodeResource(getResources(),R.mipmap.ic_company); markerOptions.icon(BitmapDescriptorFactory.fromBitmap(companyIcon)); //设置marker锚点偏移量 markerOptions.anchor(0.5f,0.5f); aMap.addMarker(markerOptions); //添加圆形面范围标识 CircleOptions circleOptions = new CircleOptions(); circleOptions.center(latLng); circleOptions.strokeWidth(0); circleOptions.fillColor(getResources().getColor(R.color.light_blue)); circleOptions.radius(200); aMap.addCircle(circleOptions); } @Override public void activate(OnLocationChangedListener onLocationChangedListener) { locationChangedListener = onLocationChangedListener; } @Override public void deactivate() { locationChangedListener = null; if (aMapLocationClient != null) { aMapLocationClient.stopLocation(); aMapLocationClient.onDestroy(); } aMapLocationClient = null; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mapView.onCreate(savedInstanceState); } @Override protected void onResume() { super.onResume(); mapView.onResume(); } @Override protected void onPause() { super.onPause(); mapView.onPause(); deactivate(); } @Override protected void onDestroy() { super.onDestroy(); mapView.onDestroy(); if (aMapLocationClient != null) { aMapLocationClient.onDestroy(); } } @Override public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { super.onSaveInstanceState(outState, outPersistentState); mapView.onSaveInstanceState(outState); }}
更多相关文章
- Android os设备谎言分辨率的解决方案
- Android高德地图获取当前地理位置(不显示地图只获取当前位置)
- android google地图开发总结——获取google地图开发密匙
- DataBinding赋值本地图片src
- android adb 通过adb连接制定设备
- Android 学习 设备管理器勾选后不能再取消了
- Android调起高德地图