protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /** * 使用地图sdk前需先初始化BMapManager. * BMapManager是全局的,可为多个MapView共用,它需要地图模块创建前创建, * 并在地图地图模块销毁后销毁,只要还有地图模块在使用,BMapManager就不应该销毁 */ DemoApplication app = (DemoApplication)this.Application; if (app.mBMapManager == null) { app.mBMapManager = new BMapManager(ApplicationContext); /** * 如果BMapManager没有初始化则初始化BMapManager */ app.mBMapManager.Init(new DemoApplication.MyGeneralListener()); } SetContentView(Resource.Layout.activity_locationoverlay); ICharSequence titleLable = new String("定位功能"); Title = titleLable.ToString(); myListener = new MyLocationListenner(this); requestLocButton = FindViewById<Button>(Resource.Id.button1); mCurBtnType = E_BUTTON_TYPE.LOC; Android.Views.View.IOnClickListener btnClickListener = new BtnClickListenerImpl(this); requestLocButton.SetOnClickListener(btnClickListener); RadioGroup group = this.FindViewById<RadioGroup>(Resource.Id.radioGroup); radioButtonListener = new RadioButtonListenerImpl(this); group.SetOnCheckedChangeListener(radioButtonListener); //地图初始化 mMapView = FindViewById<MyLocationMapView>(Resource.Id.bmapView); mMapController = mMapView.Controller; mMapView.Controller.SetZoom(14); mMapView.Controller.EnableClick(true); mMapView.SetBuiltInZoomControls(true); //创建 弹出泡泡图层 CreatePaopao(); //定位初始化 mLocClient = new LocationClient(this); locData = new LocationData(); mLocClient.RegisterLocationListener(myListener); LocationClientOption option = new LocationClientOption(); option.OpenGps = true;//打开gps option.CoorType = "bd09ll"; //设置坐标类型 option.ScanSpan = 1000; mLocClient.LocOption = option; mLocClient.Start(); //定位图层初始化 myLocationOverlay = new LocationOverlay(this, mMapView); //设置定位数据 myLocationOverlay.SetData(locData); //添加定位图层 mMapView.Overlays.Add(myLocationOverlay); myLocationOverlay.EnableCompass(); //修改定位数据后刷新图层生效 mMapView.Refresh(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_location); myListener = new MyLocationListenner(this); requestLocButton = FindViewById<Button>(Resource.Id.button1); mCurrentMode = MyLocationConfigeration.LocationMode.Normal; requestLocButton.Text = "��ͨ"; requestLocButton.Click += delegate { if (mCurrentMode.Equals(MyLocationConfigeration.LocationMode.Normal)) { requestLocButton.Text = "����"; mCurrentMode = MyLocationConfigeration.LocationMode.Following; mBaiduMap .SetMyLocationConfigeration(new MyLocationConfigeration( mCurrentMode, true, mCurrentMarker)); } else if (mCurrentMode.Equals(MyLocationConfigeration.LocationMode.Compass)) { requestLocButton.Text = "��ͨ"; mCurrentMode = MyLocationConfigeration.LocationMode.Normal; mBaiduMap .SetMyLocationConfigeration(new MyLocationConfigeration( mCurrentMode, true, mCurrentMarker)); } else if (mCurrentMode.Equals(MyLocationConfigeration.LocationMode.Following)) { requestLocButton.Text = "����"; mCurrentMode = MyLocationConfigeration.LocationMode.Compass; mBaiduMap .SetMyLocationConfigeration(new MyLocationConfigeration( mCurrentMode, true, mCurrentMarker)); } #region [ �ӵ�, ���˼�������, ��ʱ����C#ʵ��, ʹ������� if/else... ] //switch (mCurrentMode) //{ // case MyLocationConfigeration.LocationMode.Normal: // requestLocButton.Text = "����"; // mCurrentMode = MyLocationConfigeration.LocationMode.Following; // mBaiduMap // .SetMyLocationConfigeration(new MyLocationConfigeration( // mCurrentMode, true, mCurrentMarker)); // break; // case MyLocationConfigeration.LocationMode.Compass: // requestLocButton.Text = "��ͨ"; // mCurrentMode = MyLocationConfigeration.LocationMode.Normal; // mBaiduMap // .SetMyLocationConfigeration(new MyLocationConfigeration( // mCurrentMode, true, mCurrentMarker)); // break; // case MyLocationConfigeration.LocationMode.Following: // requestLocButton.Text = "����"; // mCurrentMode = MyLocationConfigeration.LocationMode.Compass; // mBaiduMap // .SetMyLocationConfigeration(new MyLocationConfigeration( // mCurrentMode, true, mCurrentMarker)); // break; //} #endregion }; RadioGroup group = this.FindViewById<RadioGroup>(Resource.Id.radioGroup); // group.CheckedChange += delegate(object sender, RadioGroup.CheckedChangeEventArgs args) { }; group.CheckedChange += (sender, args) => { int CheckedId = args.CheckedId; if (CheckedId == Resource.Id.defaulticon) { // ����null�ָ�Ĭ��ͼ�� mCurrentMarker = null; mBaiduMap .SetMyLocationConfigeration(new MyLocationConfigeration( mCurrentMode, true, null)); } if (CheckedId == Resource.Id.customicon) { // ��Ϊ�Զ���marker mCurrentMarker = BitmapDescriptorFactory .FromResource(Resource.Drawable.icon_geo); mBaiduMap .SetMyLocationConfigeration(new MyLocationConfigeration( mCurrentMode, true, mCurrentMarker)); } }; // ��ͼ��ʼ�� mMapView = FindViewById<MapView>(Resource.Id.bmapView); mBaiduMap = mMapView.Map; // �����λͼ�� mBaiduMap.MyLocationEnabled = true; // ��λ��ʼ�� mLocClient = new LocationClient(this); mLocClient.RegisterLocationListener(myListener); LocationClientOption option = new LocationClientOption(); option.OpenGps = true;// ��gps option.CoorType = "bd09ll"; // ������������ option.ScanSpan = 1000; mLocClient.LocOption = option; mLocClient.Start(); }