protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it mapView = FindViewById <MapView>(Resource.Id.mapView); button = FindViewById <Button>(Resource.Id.myButton); button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); }; mapView.OnCreate(savedInstanceState); locationClient = new AMapLocationClient(this.ApplicationContext); locationClientOption = new AMapLocationClientOption(); locationClientOption.SetWifiActiveScan(false); locationClientOption.SetMockEnable(true); locationClientOption.SetLocationMode(AMapLocationClientOption.AMapLocationMode.DeviceSensors); locationClient.SetLocationOption(locationClientOption); locationClient.Location += AMapLocationClient_Location; if (aMap == null) { aMap = mapView.Map; if (lastCamera == null) { lastCamera = CameraUpdateFactory.NewLatLngZoom(new LatLng(lastPositionArray[0], lastPositionArray[1]), 15); } aMap.MoveCamera(lastCamera); if (locationStyle == null) { locationStyle = new MyLocationStyle(); locationStyle.ShowMyLocation(true); locationStyle.InvokeMyLocationType(MyLocationStyle.LocationTypeFollow); } aMap.SetMyLocationStyle(locationStyle); aMap.MyLocationEnabled = true; aMap.UiSettings.MyLocationButtonEnabled = true; //设置默认定位按钮是否显示,非必需设置。 locationClient.StartLocation(); //aMap. } }
private void InitLocation() { //声明mlocationClient对象 LocationClient = new AMapLocationClient(this); //初始化定位参数 AMapLocationClientOption mLocationOption = new AMapLocationClientOption(); //设置定位监听 LocationClient.SetLocationListener(new LocationListener(this)); //设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式 mLocationOption.SetLocationMode(AMapLocationClientOption.AMapLocationMode.HightAccuracy); //设置定位间隔,单位毫秒,默认为2000ms mLocationOption.SetInterval(2000); //设置定位参数 LocationClient.SetLocationOption(mLocationOption); // 此方法为每隔固定时间会发起一次定位请求,为了减少电量消耗或网络流量消耗, // 注意设置合适的定位时间的间隔(最小间隔支持为1000ms),并且在合适时间调用stopLocation()方法来取消定位请求 // 在定位结束后,在合适的生命周期调用onDestroy()方法 // 在单次定位情况下,定位无论成功与否,都无需调用stopLocation()方法移除请求,定位sdk内部会移除 //启动定位 LocationClient.StartLocation(); }