/**
* 初始化方向传感器
*/
private void initOritationListener() {
myOrientationListener = new MyOrientationListener(
getApplicationContext());
myOrientationListener
.setOnOrientationListener(new OnOrientationListener() {
@Override
public void onOrientationChanged(float x) {
mXDirection = (int) x;
if (marker != null) {
marker.remove();
}
//定义Maker坐标点
LatLng point = new LatLng(39.963175, 116.400244);
//构建Marker图标
BitmapDescriptor bitmap = BitmapDescriptorFactory
.fromResource(R.drawable.icon_marka);
//构建MarkerOption,用于在地图上添加Marker
OverlayOptions option = new MarkerOptions()
.position(point)
.icon(bitmap);
//在地图上添加Marker,并显示
marker = (Marker) (mBaiduMap.addOverlay(option));
marker.setRotate(x); //实现覆盖物偏转 x为偏转的角度
Bundle bundle = new Bundle();
marker.setExtraInfo(bundle);
}
});
}
在方向传感器中 onOrientationChanged(float x) 中 得到标记物marker 给marker设置setRotate(偏移量--x)
还要把上一次的marker清空,要不会出现很多