* 初始化方向传感器
*/
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清空,要不会出现很多
LatLng p = new LatLng(latitude,longitude)补充一下p是这个
OverlayOptions option = new MarkerOptions().position(p).icon(bitmap)0xAAFFFF00
mBaiduMap.addOverlay(option)0xFFFF00FF
mBaiduMap.addOverlay(option)
加图片
OverlayOptions textOption = new TextOptions().bgColor(0xFFE33539)
.fontSize(32).fontColor(0xFFFFFFFF).text(文字).rotate(0)
.position(p)
mBaiduMap.addOverlay(textOption)
加文字
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)