Esempio n. 1
0
        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.
            }
        }