use of com.amap.api.maps.model.MyLocationStyle 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);
}
}
use of com.amap.api.maps.model.MyLocationStyle 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);
}
}
});
}
Aggregations