百度地图方向定位
来源:互联网 发布:git ignore mac 编辑:程序博客网 时间:2024/06/06 01:57
private MyOrientationListener mMyOrientationListener;private float mCurrentX; //方向偏移private BitmapDescriptor mBitmapDescriptor;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //方向传感器监听函数 mMyOrientationListener=new MyOrientationListener(this);mMyOrientationListener.setOnOrientationListener(new MyOrientationListener.OnOrientationListener() {@Override public void onOrientationChanged(float x) { mCurrentX=x; }});}protected void onStart() { super.onStart(); //开启方向传感器 mMyOrientationListener.start(); }/** * 百度地图定位监听 */ public class MyLocationListener implements BDLocationListener { @Override public void onReceiveLocation(BDLocation location) { //Receive Location if (location.getCity()!=null&&!location.getCity().equals("")){ mLatitude = location.getLatitude(); // mLongitude = location.getLongitude(); MyLocationData locData = new MyLocationData.Builder() .accuracy(location.getRadius()) // 此处设置开发者获取到的方向信息,顺时针0-360 .direction(mCurrentX).latitude(mLatitude) .longitude(mLongitude).build(); // 设置定位数据 mMapView.getMap().setMyLocationData(locData); initLocalMark(); } }/** * 初始化当前定位标记 */ public void initLocalMark(){//定位标志图形mBitmapDescriptor = BitmapDescriptorFactory.fromResource(R.mipmap.mylocal);MyLocationConfiguration config=new MyLocationConfiguration(MyLocationConfiguration.LocationMode.NORMAL,true,mBitmapDescriptor); mMapView.getMap().setMyLocationConfigeration(config);}
@Overrideprotected void onStop() { super.onStop(); mMapView.getMap().setMyLocationEnabled(false); //结束定位 if(mLocationClient.isStarted()){ mLocationClient.stop(); //关闭方向传感器 mMyOrientationListener.stop(); }}public class MyOrientationListener implements SensorEventListener{ private SensorManager mSensorManager; private Context mContext; private Sensor mSensor; private float lastX; public MyOrientationListener(Context context) { this.mContext = context; } @SuppressWarnings("deprecation") public void start() { mSensorManager = (SensorManager) mContext .getSystemService(Context.SENSOR_SERVICE); if (mSensorManager != null) { mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); } if (mSensor != null) { mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_UI); } } public void stop() { mSensorManager.unregisterListener(this); } @Override public void onAccuracyChanged(Sensor arg0, int arg1) { // TODO Auto-generated method stub } @SuppressWarnings( { "deprecation" }) @Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) { float x = event.values[SensorManager.DATA_X]; if (Math.abs(x - lastX) > 1.0) { if (mOnOrientationListener != null) { mOnOrientationListener.onOrientationChanged(x); } } lastX = x; } } private OnOrientationListener mOnOrientationListener; public void setOnOrientationListener( OnOrientationListener mOnOrientationListener) { this.mOnOrientationListener = mOnOrientationListener; } public interface OnOrientationListener { void onOrientationChanged(float x); }}
0 0
- 百度地图方向定位
- 百度地图Marker的定位和方向
- android--百度地图--方向定位+覆盖物显示
- 百度地图定位当前并且加上方向传感器
- 百度地图定位以及方向传感器的调用
- 百度地图植入教程(3)—定位与方向传感器
- 百度地图植入android应用系列教程二实现百度地图定位及方向传感器
- 百度地图 定位 地图
- 百度地图,百度定位。
- android 百度地图系列之结合方向传感器的地图定位
- 百度地图之定位
- Android 百度地图 定位
- Android百度地图定位
- 百度地图定位基础
- 百度地图多点定位
- 百度地图定位问题
- Android 百度地图定位
- 百度地图 定位问题
- 服务器运维脚本记录
- 15 个 Android 通用流行框架大全
- CakePHP3的Auth
- Android利用JXL框架读取excel
- Ubuntu 12.04下fcitx安装谷歌搜狗输入法
- 百度地图方向定位
- AFNetworking3.xPost请求- “请求对象无法序列化”处理及:App Transport Security has blocked a cleartext HTTP (http://)
- iOS学习笔记-集成环信UI3.0
- jQuery 遍历 - find() 方法
- INSERT INTO t_inertupdate_tmp(a,b,c) select * 表名 where 字段名 is not null
- ubuntu下安装shadowsocks-qt5(影梭)
- 我生命中的钱事:养家!
- 在OC项目中添加Swift文件并实现混合编程
- HTML, JS, 笔记01