|
发表帖子
API/SDK版本号: |
n |
产品: |
定位 |
手机型号: |
android |
使用接口: |
|
代码用的是官方示例中心的:定位图标指示方向 ,https://lbs.amap.com/dev/demo/location-rotation-effect#Android在持续定位的过程中,移动地图后镜头会被拉回原点,以定位图标为地图中心点。
希望拖动后不移动镜头。
定位类型:aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
代码部分:
private void setUpMap() {
aMap.setLocationSource(this);// 设置定位监听
aMap.getUiSettings().setMyLocationButtonEnabled(true);// 设置默认定位按钮是否显示
aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
// 设置定位的类型为定位模式 ,可以由定位、跟随或地图根据面向方向旋转几种
aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
}
public void activate(OnLocationChangedListener listener) {
mListener = listener;
if (mlocationClient == null) {
mlocationClient = new AMapLocationClient(this);
mLocationOption = new AMapLocationClientOption();
//设置定位监听
mlocationClient.setLocationListener(this);
//设置为高精度定位模式
mLocationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
//设置定位参数
mlocationClient.setLocationOption(mLocationOption);
mlocationClient.startLocation();
}
}
public void onLocationChanged(AMapLocation amapLocation) {
if (mListener != null && amapLocation != null) {
if (amapLocation != null&& amapLocation.getErrorCode() == 0) {
mLocationErrText.setVisibility(View.GONE);
LatLng location = new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude());
if (!mFirstFix) {
mFirstFix = true;
addCircle(location, amapLocation.getAccuracy());//添加定位精度圆
addMarker(location);//添加定位图标
mSensorHelper.setCurrentMarker(mLocMarker);//定位图标旋转
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location,18));
} else {
mCircle.setCenter(location);
mCircle.setRadius(amapLocation.getAccuracy());
mLocMarker.setPosition(location);
aMap.moveCamera(CameraUpdateFactory.changeLatLng(location));
}
} else {
String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();
Log.e("AmapErr", errText);
mLocationErrText.setVisibility(View.VISIBLE);
mLocationErrText.setText(errText);
}
}
}
|
|