当前位置: 首页>>代码示例>>C#>>正文


C# CLLocationManager类代码示例

本文整理汇总了C#中CLLocationManager的典型用法代码示例。如果您正苦于以下问题:C# CLLocationManager类的具体用法?C# CLLocationManager怎么用?C# CLLocationManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CLLocationManager类属于命名空间,在下文中一共展示了CLLocationManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
            ConfigureView();

            _iPhoneLocationManager = new CLLocationManager();
            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                _iPhoneLocationManager.RequestWhenInUseAuthorization();
            }

            mapView.ShowsUserLocation = true;

            if (mapView.UserLocationVisible)
            {
                UpdateUiCoords();
            }

            _iPhoneLocationManager.DesiredAccuracy = 1000; // 1000 meters/1 kilometer

            mapView.DidUpdateUserLocation += (sender, e) =>
            {
                if (mapView.UserLocation != null)
                {
                    CLLocationCoordinate2D coords = mapView.UserLocation.Coordinate;
                    MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(2), MilesToLongitudeDegrees(2, coords.Latitude));
                    mapView.Region = new MKCoordinateRegion(coords, span);
                    UpdateUiCoords();
                }
            };
        }
开发者ID:modulexcite,项目名称:CrmSetAccountLocationXamarin,代码行数:33,代码来源:DetailViewController.cs

示例2: FinishedLaunching

        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            global::Xamarin.FormsMaps.Init();

            locationManager = new CLLocationManager
            {
                DesiredAccuracy = CLLocation.AccuracyBest
            };

            locationManager.Failed += (object sender, NSErrorEventArgs e) =>
            {
                var alert = new UIAlertView(){ Title = "Location manager failed", Message = "The location updater has failed" };
                alert.Show();
                locationManager.StopUpdatingLocation();
            };

            locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) =>
            {
                var newloc = string.Format("{0},{1}", e.Locations[0].Coordinate.Longitude, e.Locations[0].Coordinate.Latitude);
                App.Self.ChangedClass.BroadcastIt("location", newloc);
            };

            locationManager.StartUpdatingLocation();

            LoadApplication(new App());

            return base.FinishedLaunching(app, options);
        }
开发者ID:nodoid,项目名称:GPSPush,代码行数:29,代码来源:AppDelegate.cs

示例3: DoLocationAndUpdated

        /// <summary>
        /// get the location of user and update to server
        /// </summary>
        public static void DoLocationAndUpdated()
        {
            Location.iPhoneLocationManager = new CLLocationManager ();
            Location.iPhoneLocationManager.DesiredAccuracy = 5; // 1000 meters/1 kilometer
            // if this is iOs6
            if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
                Location.iPhoneLocationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
                    CLLocation newLocation = e.Locations [e.Locations.Length - 1];
                    Utils.Log("ios6");
                    Location.UpdateLocationToServer(newLocation.Coordinate.Latitude.ToString (), newLocation.Coordinate.Longitude.ToString ());
                    //iPhoneLocationManager.StopUpdatingLocation();
                };
            }
            // if it is iOs 5 or lower
            else {
                Location.iPhoneLocationManager.UpdatedLocation += (object sender, CLLocationUpdatedEventArgs e) => {
                    CLLocation newLocation =  e.NewLocation;
                    Utils.Log("ios5");
                    Location.UpdateLocationToServer(newLocation.Coordinate.Latitude.ToString (), newLocation.Coordinate.Longitude.ToString ());
                    //iPhoneLocationManager.StopUpdatingLocation();
                };
            }

            if (CLLocationManager.LocationServicesEnabled) iPhoneLocationManager.StartUpdatingLocation ();
        }
开发者ID:hoangnm284,项目名称:MobileUtils,代码行数:28,代码来源:Location.cs

示例4: Start

		public void Start ()
		{
			if (CLLocationManager.LocationServicesEnabled) {
				lman = new CLLocationManager {
					DesiredAccuracy = CLLocation.AccuracyBest,
				};

				lman.RequestWhenInUseAuthorization ();

				lman.LocationsUpdated += (sender, e) => {
					var loc = e.Locations [0];
					Timestamp = loc.Timestamp;
					Location = new Location (loc.Coordinate.Latitude, loc.Coordinate.Longitude, loc.Altitude);
//					Console.WriteLine (Location);
					HorizontalAccuracy = loc.HorizontalAccuracy;
					VerticalAccuracy = loc.VerticalAccuracy;
					LocationReceived (this, EventArgs.Empty);
				};

				lman.UpdatedHeading += (sender, e) => {
					Heading = e.NewHeading.TrueHeading;
//					Console.WriteLine ("Heading: {0}", Heading);
				};

				lman.StartUpdatingLocation ();
				lman.StartUpdatingHeading ();
			}
		}
开发者ID:jorik041,项目名称:ARDemo,代码行数:28,代码来源:LocationSensor.cs

示例5: GPSTracker

 public GPSTracker()
 {
     if (CLLocationManager.LocationServicesEnabled)
     {
         _manager = new CLLocationManager();
     }
 }
开发者ID:Fedorm,项目名称:core-master,代码行数:7,代码来源:GPSTracker.cs

示例6: Init

        public void Init(Action<PLVPaylevenStatus> action, string currency)
        {
            locationManager = new CLLocationManager();
            // TODO: Get current location

            paylevenManager = new PaylevenManager(action, currency, 52.252505, 21.023012);
        }
开发者ID:Applandeo,项目名称:PaylevenSample,代码行数:7,代码来源:Payleven.cs

示例7: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            int speedSystem = 0;

            kmhourButton.ValueChanged += (sender,e) => {
                speedSystem = kmhourButton.SelectedSegment;
            };

            _iPhoneLocationManager = new CLLocationManager ();
            _iPhoneLocationManager.DesiredAccuracy = 1000; // 1000 meters/1 kilometer

            //update location based on the specified metric system
            _iPhoneLocationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
                UpdateLocation (speedSystem, e.Locations [e.Locations.Length - 1].Speed);
            };

            if (CLLocationManager.LocationServicesEnabled)
                _iPhoneLocationManager.StartUpdatingLocation ();

            //if viewmap button is touched then display the map
            ViewMap.TouchUpInside += (object sender, EventArgs e) => {
                if (_speedController == null)
                    _speedController = new SpeedController();
                    //_speedController = new MapController();
                NavigationController.PushViewController(_speedController, true);
            };
        }
开发者ID:jakupllarif,项目名称:Senior-Project,代码行数:29,代码来源:CurrentSpeedController.cs

示例8: FinishedLaunching

        public override void FinishedLaunching(UIApplication application)
        {
            locationManager = new CLLocationManager ();

            if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
                locationManager.RequestWhenInUseAuthorization ();
            }
            // A user can transition in or out of a region while the application is not running.
            // When this happens CoreLocation will launch the application momentarily, call this delegate method
            // and we will let the user know via a local notification.
            locationManager.DidDetermineState += (sender, e) => {
                string body = null;
                if (e.State == CLRegionState.Inside)
                    body = "You're inside the region";
                else if (e.State == CLRegionState.Outside)
                    body = "You're outside the region";

                if (body != null) {
                    var notification = new UILocalNotification () { AlertBody = body };

                    // If the application is in the foreground, it will get called back to ReceivedLocalNotification
                    // If its not, iOS will display the notification to the user.
                    UIApplication.SharedApplication.PresentLocalNotificationNow (notification);
                }
            };
        }
开发者ID:Rajneesh360Logica,项目名称:monotouch-samples,代码行数:26,代码来源:AppDelegate.cs

示例9: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            locMan = new CLLocationManager();
            locMan.RequestWhenInUseAuthorization();
            locMan.RequestAlwaysAuthorization();
            // Geocode a city to get a CLCircularRegion,
            // and then use our location manager to set up a geofence
            button.TouchUpInside += (o, e) => {

                // clean up monitoring of old region so they don't pile up
                if(region != null)
                {
                    locMan.StopMonitoring(region);
                }

                // Geocode city location to create a CLCircularRegion - what we need for geofencing!
                var taskCoding = geocoder.GeocodeAddressAsync ("Cupertino");
                taskCoding.ContinueWith ((addresses) => {
                    CLPlacemark placemark = addresses.Result [0];
                    region = (CLCircularRegion)placemark.Region;
                    locMan.StartMonitoring(region);

                });
            };

            // This gets called even when the app is in the background - try it!
            locMan.RegionEntered += (sender, e) => {
                Console.WriteLine("You've entered the region");
            };

            locMan.RegionLeft += (sender, e) => {
                Console.WriteLine("You've left the region");
            };
        }
开发者ID:yofanana,项目名称:recipes,代码行数:35,代码来源:GeofencingViewController.cs

示例10: GeolocationSingleUpdateDelegate

        public GeolocationSingleUpdateDelegate(CLLocationManager manager, double desiredAccuracy, bool includeHeading, int timeout, CancellationToken cancelToken)
        {
            this.manager = manager;
            this.tcs = new TaskCompletionSource<Position>(manager);
            this.desiredAccuracy = desiredAccuracy;
            this.includeHeading = includeHeading;

            if (timeout != Timeout.Infinite)
            {
                Timer t = null;
                t = new Timer(s =>
                {
                    if (this.haveLocation)
                        this.tcs.TrySetResult(new Position(this.position));
                    else
                        this.tcs.TrySetCanceled();

                    StopListening();
                    t.Dispose();
                }, null, timeout, 0);
            }

            cancelToken.Register(() =>
            {
                StopListening();
                this.tcs.TrySetCanceled();
            });
        }
开发者ID:jakkaj,项目名称:Xamling-Core,代码行数:28,代码来源:GeolocationSingleUpdateDelegate.cs

示例11: LocationsUpdated

 public override void LocationsUpdated(CLLocationManager manager, CLLocation[] locations)
 {
     Task.Run (async () =>  {await AppDelegate.FlicService.RefreshPendingConnections();});
     foreach(var loc in locations) {
         Console.WriteLine(loc);
     }
 }
开发者ID:bytedreamer,项目名称:BusyBot-iOS,代码行数:7,代码来源:MainTabBarController.cs

示例12: LocationTestService

 public LocationTestService()
 {
     locationManager = new CLLocationManager();
     locationManager.LocationsUpdated += LocationsUpdated;
     locationManager.DistanceFilter = 10;
     locationManager.DesiredAccuracy = CLLocation.AccuracyBest;
 }
开发者ID:pgrzmil,项目名称:XamarinResearch,代码行数:7,代码来源:LocationTestService.cs

示例13: UpdatedLocation

 public override void UpdatedLocation (CLLocationManager manager, CLLocation newLocation, CLLocation oldLocation)
 {                
     _helper.Locations.Add (newLocation);
     
     if (_helper.LocationAdded != null)
         _helper.LocationAdded (_helper, new LocationEventArgs (newLocation));
 }
开发者ID:enricos,项目名称:learning_monotouch_code,代码行数:7,代码来源:LocationHelper.cs

示例14: ViewDidLoad

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			locationManager = new CLLocationManager ();
			locationManager.AuthorizationChanged += OnAuthorizationChanged;
			locationManager.LocationsUpdated += OnLocationsUpdated;
			locationManager.DesiredAccuracy = CLLocation.AccuracyBest;
			locationManager.ActivityType = CLActivityType.Other;

			// We setup a pair of anchors that will define how the floorplan image, maps to geographic co-ordinates
			var anchor1 = new GeoAnchor {
				LatitudeLongitude = new CLLocationCoordinate2D (37.770511, -122.465810),
				Pixel = new CGPoint (12, 18)
			};

			var anchor2 = new GeoAnchor {
				LatitudeLongitude = new CLLocationCoordinate2D (37.769125, -122.466356),
				Pixel = new CGPoint (481, 815)
			};

			anchorPair = new Tuple<GeoAnchor, GeoAnchor> (anchor1, anchor2);

			// Initialize the coordinate system converter with two anchor points.
			coordinateConverter = new CoordinateConverter (anchorPair);
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:26,代码来源:MainViewController.cs

示例15: StartTimer

        public void StartTimer(CLLocationManager manager)
        {
            hasLastAttempt = false;

            Manager = manager;
            locationTimer = NSTimer.CreateScheduledTimer(TimeSpan.FromSeconds(30), TerminateLocationUpdate);
        }
开发者ID:nicwise,项目名称:londonbikeapp,代码行数:7,代码来源:NearDialogViewController.cs


注:本文中的CLLocationManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。