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


C# CLLocationManager.StartUpdatingLocation方法代码示例

本文整理汇总了C#中CLLocationManager.StartUpdatingLocation方法的典型用法代码示例。如果您正苦于以下问题:C# CLLocationManager.StartUpdatingLocation方法的具体用法?C# CLLocationManager.StartUpdatingLocation怎么用?C# CLLocationManager.StartUpdatingLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CLLocationManager的用法示例。


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

示例1: 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

示例2: FinishedLaunching

		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			window = new UIWindow (UIScreen.MainScreen.Bounds);

			var what = new EntryElement ("What ?", "e.g. pizza", String.Empty);
			var where = new EntryElement ("Where ?", "here", String.Empty);

			var section = new Section ();
			if (CLLocationManager.LocationServicesEnabled) {
				lm = new CLLocationManager ();
				lm.LocationsUpdated += delegate (object sender, CLLocationsUpdatedEventArgs e) {
					lm.StopUpdatingLocation ();
					here = e.Locations [e.Locations.Length - 1];
					var coord = here.Coordinate;
					where.Value = String.Format ("{0:F4}, {1:F4}", coord.Longitude, coord.Latitude);
				};
				section.Add (new StringElement ("Get Current Location", delegate {
					lm.StartUpdatingLocation ();
				}));
			}

			section.Add (new StringElement ("Search...", async delegate {
				await SearchAsync (what.Value, where.Value);
			}));

			var root = new RootElement ("MapKit Search Sample") {
				new Section ("MapKit Search Sample") { what, where },
				section
			};
			window.RootViewController = new UINavigationController (new DialogViewController (root, true));
			window.MakeKeyAndVisible ();
			return true;
		}
开发者ID:GSerjo,项目名称:monotouch-samples,代码行数:33,代码来源:AppDelegate.cs

示例3: 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

示例4: 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

示例5: 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

示例6: RequestLocation

 public static void RequestLocation(Action<CLLocation> callback)
 {
     locationManager = new CLLocationManager () {
         DesiredAccuracy = CLLocation.AccuracyBest,
         Delegate = new MyCLLocationManagerDelegate (callback),
         DistanceFilter = 1000f
     };
     if (CLLocationManager.LocationServicesEnabled)
         locationManager.StartUpdatingLocation ();
 }
开发者ID:azcoov,项目名称:MonoTouch-CoreLocation-Example,代码行数:10,代码来源:Utils.cs

示例7: ViewDidLoad

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

            // Perform any additional setup after loading the view, typically from a nib.
            iPhoneLocationManager = new CLLocationManager();
            iPhoneLocationManager.Delegate = new LocationDelegate(this);

            iPhoneLocationManager.StartUpdatingLocation();
            iPhoneLocationManager.StartUpdatingHeading();
        }
开发者ID:in-the-keyhole,项目名称:khs-blog-examples,代码行数:11,代码来源:CurrentTemperatureViewController.cs

示例8: Initialize

		public static void Initialize()
		{
			CoreLocationManager = new CLLocationManager();
			
			CoreLocationManager.StartUpdatingLocation();
			
			CoreLocationManager.UpdatedHeading += HandleCoreLocationManagerUpdatedHeading;
			CoreLocationManager.UpdatedLocation += HandleCoreLocationManagerUpdatedLocation;
			
			UpdateLocationTimer = NSTimer.CreateRepeatingTimer(TimeSpan.FromMinutes(1), InitializeLocationUpdate);
			UpdateHeadingTimer =NSTimer.CreateRepeatingTimer(TimeSpan.FromMinutes(1), InitializeHeadingUpdate);
		}
开发者ID:GSerjo,项目名称:Seminars,代码行数:12,代码来源:LocationManager.cs

示例9: LocationPrivacyManager

		public LocationPrivacyManager ()
		{
			locationManager = new CLLocationManager ();

			// If previously allowed, start location manager
			if (CLLocationManager.Status == CLAuthorizationStatus.AuthorizedWhenInUse)
				locationManager.StartUpdatingLocation();

			locationManager.Failed += OnFailed;
			locationManager.LocationsUpdated += OnLocationsUpdated;
			locationManager.AuthorizationChanged += OnAuthorizationChanged;
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:12,代码来源:LocationPrivacyManager.cs

示例10: PlatformSpecificStart

        protected override void PlatformSpecificStart(MvxLocationOptions options)
        {
            lock (this)
            {
                if (_locationManager != null)
                    throw new MvxException("You cannot start the MvxLocation service more than once");

                _locationManager = new CLLocationManager();
                _locationManager.Delegate = new LocationDelegate(this);

                if (options.MovementThresholdInM > 0)
                {
                    _locationManager.DistanceFilter = options.MovementThresholdInM;
                }
                else
                {
                    _locationManager.DistanceFilter = CLLocationDistance.FilterNone;
                }
                _locationManager.DesiredAccuracy = options.Accuracy == MvxLocationAccuracy.Fine ? CLLocation.AccuracyBest : CLLocation.AccuracyKilometer;
                if (options.TimeBetweenUpdates > TimeSpan.Zero)
                {
                    Mvx.Warning("TimeBetweenUpdates specified for MvxLocationOptions - but this is not supported in iOS");
                }


				if (options.TrackingMode == MvxLocationTrackingMode.Background)
				{
					if (IsIOS8orHigher)
					{
						_locationManager.RequestAlwaysAuthorization ();
					}
					else
					{
						Mvx.Warning ("MvxLocationTrackingMode.Background is not supported for iOS before 8");
					}
				}
				else
				{
					if (IsIOS8orHigher)
					{
						_locationManager.RequestWhenInUseAuthorization ();
					}
				}

                if (CLLocationManager.HeadingAvailable)
                    _locationManager.StartUpdatingHeading();

                _locationManager.StartUpdatingLocation();
            }
        }
开发者ID:Everbridge,项目名称:sm-MvvmCross,代码行数:50,代码来源:MvxTouchLocationWatcher.cs

示例11: PlatformSpecificStart

        protected override void PlatformSpecificStart(MvxGeoLocationOptions options)
        {
            lock (this)
            {
                if (_locationManager != null)
                    throw new MvxException("You cannot start the MvxLocation service more than once");

                _locationManager = new CLLocationManager();
                _locationManager.Delegate = new LocationDelegate(this);

                //_locationManager.DesiredAccuracy = options.EnableHighAccuracy ? Accuracy.Fine : Accuracy.Coarse;
                _locationManager.StartUpdatingLocation();
            }
        }
开发者ID:JoanMiro,项目名称:MvxMod,代码行数:14,代码来源:MvxTouchGeoLocationWatcher.cs

示例12: ViewDidLoad

		public override void ViewDidLoad ()
		{
			// all your base
			base.ViewDidLoad ();
			
			// load the appropriate view, based on the device type
			this.LoadViewForDevice ();

			// initialize our location manager and callback handler
			iPhoneLocationManager = new CLLocationManager ();
			
			// uncomment this if you want to use the delegate pattern:
			//locationDelegate = new LocationDelegate (mainScreen);
			//iPhoneLocationManager.Delegate = locationDelegate;
			
			// you can set the update threshold and accuracy if you want:
			//iPhoneLocationManager.DistanceFilter = 10; // move ten meters before updating
			//iPhoneLocationManager.HeadingFilter = 3; // move 3 degrees before updating
			
			// you can also set the desired accuracy:
			iPhoneLocationManager.DesiredAccuracy = 1000; // 1000 meters/1 kilometer
			// you can also use presets, which simply evalute to a double value:
			//iPhoneLocationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters;
			
			// handle the updated location method and update the UI
			if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
				iPhoneLocationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
					UpdateLocation (mainScreen, e.Locations [e.Locations.Length - 1]);
				};
			} else {
				// this won't be called on iOS 6 (deprecated)
				iPhoneLocationManager.UpdatedLocation += (object sender, CLLocationUpdatedEventArgs e) => {
					UpdateLocation (mainScreen, e.NewLocation);
				};
			}
			
			// handle the updated heading method and update the UI
			iPhoneLocationManager.UpdatedHeading += (object sender, CLHeadingUpdatedEventArgs e) => {
				mainScreen.LblMagneticHeading.Text = e.NewHeading.MagneticHeading.ToString () + "º";
				mainScreen.LblTrueHeading.Text = e.NewHeading.TrueHeading.ToString () + "º";
			};
			
			// start updating our location, et. al.
			if (CLLocationManager.LocationServicesEnabled)
				iPhoneLocationManager.StartUpdatingLocation ();
			if (CLLocationManager.HeadingAvailable)
				iPhoneLocationManager.StartUpdatingHeading ();
		}
开发者ID:GSerjo,项目名称:monotouch-samples,代码行数:48,代码来源:MainViewController.cs

示例13: Main

	static void Main ()
	{
		NSApplication.Init ();
		
		var locationManager = new CLLocationManager ();
		locationManager.UpdatedLocation += (sender, args) => {
			var coord = args.NewLocation.Coordinate;
			Console.WriteLine ("At {0}", args.NewLocation.Description ());
			locationManager.StopUpdatingLocation ();

			Console.WriteLine (googleUrl, coord.Latitude, coord.Longitude);
			NSWorkspace.SharedWorkspace.OpenUrl (new Uri (String.Format (googleUrl, coord.Latitude, coord.Longitude)));
			
		};
		locationManager.StartUpdatingLocation ();
		NSRunLoop.Current.RunUntil (NSDate.DistantFuture);
	}
开发者ID:xamarin,项目名称:mac-samples,代码行数:17,代码来源:locator.cs

示例14: StartLocationManager

		public void StartLocationManager()
		{
			LocationManager = new CLLocationManager();

			//if (LocationManager.RespondsToSelector(new MonoTouch.ObjCRuntime.Selector("requestWhenInUseAuthorization")))
				LocationManager.RequestWhenInUseAuthorization();

			LocationManager.DistanceFilter = CLLocationDistance.FilterNone;
			LocationManager.DesiredAccuracy = CLLocation.AccuracyBest;
			LocationManager.LocationsUpdated += LocationManager_LocationsUpdated;
			LocationManager.StartUpdatingLocation();


			_isTracking = true;

			System.Diagnostics.Debug.WriteLine("Location manager started ");
		}
开发者ID:MobileFit,项目名称:CoachV2,代码行数:17,代码来源:GeoLocation.cs

示例15: StartLocationUpdates

		#pragma warning disable 0618
		public void StartLocationUpdates ()
		{
			// We need the user's permission for our app to use the GPS in iOS. This is done either by the user accepting
			// the popover when the app is first launched, or by changing the permissions for the app in Settings

			if (CLLocationManager.LocationServicesEnabled) {

                LocMgr = new CLLocationManager();
				LocMgr.DesiredAccuracy = 1; // sets the accuracy that we want in meters

                // Handle the LocationsUpdated event which is sent with >= iOS6 to indicate
                // our location (position) has changed.  
                if (UIDevice.CurrentDevice.CheckSystemVersion(6, 0))
                {
                    LocMgr.LocationsUpdated += (sender, e) =>
                    {
                        // fire our custom Location Updated event
                        LocationUpdated(this, new LocationUpdatedEventArgs(e.Locations[e.Locations.Length - 1]));
                    };
                }
                // <= iOS5 used UpdatedLocation which has been deprecated.
                else
                {
                    // This generates a warning.
                    LocMgr.UpdatedLocation += (sender, e) =>
                    {
                        // fire our custom Location Updated event
                        LocationUpdated(this, new LocationUpdatedEventArgs(e.NewLocation));
                    };
                }

				// Start our location updates
				LocMgr.StartUpdatingLocation ();

				// Get some output from our manager in case of failure
				LocMgr.Failed += (sender, e) =>
                {
                    Console.WriteLine("LocationManager failed: {0}", e.Error);
                }; 
				
			} else {

				//Let the user know that they need to enable LocationServices
				Console.WriteLine ("Location services not enabled, please enable this in your Settings");
			}
		}
开发者ID:flolovebit,项目名称:xamarin-evolve-2014,代码行数:47,代码来源:LocationManager.cs


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