public override void OnCreate() { base.OnCreate(); Log.Info(Tag, "-------------------------LocationServer OnCreate-------------------"); _context = this; _locationClient = new LocationClient(ApplicationContext); _locationClient.RegisterLocationListener(_myLocationListener); InitLocation(); }
public BaiduLBS(Android.Content.Context context) { lock (objLock) { if (sLocationClient == null) { sLocationClient = new Com.Baidu.Location.LocationClient(context); //声明LocationClient类 // sLocationClient.RegisterLocationListener(this); //注册监听函数 sLocationClient.RegisterLocationListener(this); } } }
public override void OnCreate () { base.OnCreate (); mLocationClient = new LocationClient(ApplicationContext); var option = new LocationClientOption (); option.SetIsNeedAddress (true); option.SetIsNeedLocationDescribe (true); mLocationClient.LocOption = option; mMyLocationListener = new MyLocationListener(handler, this); mLocationClient.RegisterLocationListener(mMyLocationListener); mVibrator =(Vibrator)ApplicationContext.GetSystemService(Service.VibratorService); }
private void InitialLocation() { mBaiduMap = bmapView.Map; mBaiduMap.MyLocationEnabled = true; var mLocOption = new LocationClientOption { OpenGps = true, CoorType = "bd0911", ScanSpan = 5000, AddrType = "all" }; var mLocClient = new LocationClient(this) { LocOption = mLocOption }; mLocClient.Start(); mLocClient.RequestLocation(); mLocClient.RegisterLocationListener(new MapLocationListenner { Context = this }); }
public void GetLocation() { //实例化位置客户端 _locClient = new LocationClient(ApplicationContext); //设置option的属性 LocationClientOption option = new LocationClientOption(); option.SetLocationMode(LocationClientOption.LocationMode.HightAccuracy); //可选,默认高精度,设置定位模式,高精度,低功耗,仅设备 option.CoorType = "bd09ll"; //可选,默认gcj02,设置返回的定位结果坐标系, const int interval = 0; option.ScanSpan = interval; //可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的 option.SetIsNeedAddress(true); //可选,设置是否需要地址信息,默认不需要 option.OpenGps = true; //可选,默认false,设置是否使用gps option.LocationNotify = true; //可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果 option.SetIgnoreKillProcess(true); //可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死 _locClient.LocOption = option; //给位置客户端注册位置监听器 _locClient.RegisterLocationListener(this); //启动位置客户端 _locClient.Start(); }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); mLocationClient = ((LocationApplication)Application).mLocationClient; LocationResult = (TextView)FindViewById(Resource.Id.textView1); ModeInfor= (TextView)FindViewById(Resource.Id.modeinfor); ModeInfor.Text=Resources.GetString(Resource.String.hight_accuracy_desc); ((LocationApplication)Application).mLocationResult = LocationResult; frequence = (EditText)FindViewById(Resource.Id.frequence); checkGeoLocation = (CheckBox)FindViewById(Resource.Id.geolocation); startLocation = (Button)FindViewById(Resource.Id.addfence); startLocation.Click += StartLocation_Clicked; selectMode = (RadioGroup)FindViewById(Resource.Id.selectMode); selectCoordinates= (RadioGroup)FindViewById(Resource.Id.selectCoordinates); selectMode.SetOnCheckedChangeListener (this); selectCoordinates.CheckedChange+= Select_CheckedChanged ; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); //在使用SDK各组件之前初始化context信息,传入ApplicationContext //注意该方法要再setContentView方法之前实现 SDKInitializer.Initialize(ApplicationContext); SetContentView(Resource.Layout.Main); //获取地图控件引用 //mMapView = FindViewById<MapView>(Resource.Id.bmapView); //mBaiduMap = mMapView.Map; // 地图初始化 mMapView = FindViewById<MapView>(Resource.Id.bmapView); mBaiduMap = mMapView.Map; mCurrentMode = MyLocationConfiguration.LocationMode.Normal; //requestLocButton.Text = "普通"; //requestLocButton.Click += delegate //{ if (mCurrentMode.Equals(MyLocationConfiguration.LocationMode.Normal)) { //requestLocButton.Text = "跟随"; mCurrentMode = MyLocationConfiguration.LocationMode.Following; mBaiduMap.SetMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true, mCurrentMarker)); } // else if (mCurrentMode.Equals(MyLocationConfiguration.LocationMode.Compass)) // { // requestLocButton.Text = "普通"; // mCurrentMode = MyLocationConfiguration.LocationMode.Normal; // mBaiduMap // .SetMyLocationConfigeration(new MyLocationConfiguration( // mCurrentMode, true, mCurrentMarker)); // } // else if (mCurrentMode.Equals(MyLocationConfiguration.LocationMode.Following)) // { // requestLocButton.Text = "罗盘"; // mCurrentMode = MyLocationConfiguration.LocationMode.Compass; // mBaiduMap // .SetMyLocationConfigeration(new MyLocationConfiguration( // mCurrentMode, true, mCurrentMarker)); // } //}; //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)); // } //}; // 开启定位图层 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(); }
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(); }