• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# CLLocationManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: TCLocationManager

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

			locationManager.DistanceFilter = 10;
			locationManager.Delegate = new TCLocationDelegate ();
		}
开发者ID:borain89vn,项目名称:demo2,代码行数:7,代码来源:TCLocationManager.cs


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


示例18: ViewDidLoad

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

            manager = new CLLocationManager ();

            // handle the updated location method and update the UI
            if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
                manager.LocationsUpdated += LocationsUpdated;
            } else {
                // this won't be called on iOS 6 (deprecated)
                manager.UpdatedLocation += UpdatedLocation;
            }

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

            //if (CLLocationManager.HeadingAvailable)
            //	manager.StartUpdatingHeading ();

            mapView.GetViewForAnnotation += GetAirportAnnotationView;
            mapView.RegionChanged += MapRegionChanged;
            mapType.ValueChanged += MapTypeChanged;
            MapTypeChanged (null, null);
        }
开发者ID:pahlot,项目名称:FlightLog,代码行数:25,代码来源:AirportViewController.cs


示例19: LocationManagerDidUpdateToLocationFromLocation

        public void LocationManagerDidUpdateToLocationFromLocation(CLLocationManager manager, CLLocation newLocation, CLLocation oldLocation)
        {
            // Ignore updates where nothing we care about changed
            if (oldLocation != null &&
                newLocation.Coordinate.longitude == oldLocation.Coordinate.longitude &&
                newLocation.Coordinate.latitude == oldLocation.Coordinate.latitude &&
                newLocation.HorizontalAccuracy == oldLocation.HorizontalAccuracy)
            {
                return;
            }

            // Load the HTML for displaying the Google map from a file and replace the
            // format placeholders with our location data
            NSError error;
            NSString htmlString = NSString.StringWithFormat(
                NSString.StringWithContentsOfFileEncodingError(
                NSBundle.MainBundle.PathForResourceOfType("HTMLFormatString", @"html"),
                NSStringEncoding.NSUTF8StringEncoding,out error),
                newLocation.Coordinate.latitude,
                newLocation.Coordinate.longitude,
                LatitudeRangeForLocation(newLocation),
                LongitudeRangeForLocation(newLocation));

            // Load the HTML in the WebView and set the labels
            this.webView.MainFrame.LoadHTMLStringBaseURL(htmlString, null);
            this.locationLabel.StringValue = NSString.StringWithFormat("%f, %f",
                                                                       newLocation.Coordinate.latitude, newLocation.Coordinate.longitude);
            this.accuracyLabel.StringValue = NSString.StringWithFormat("%f",
                                                                       newLocation.HorizontalAccuracy);
        }
开发者ID:Monobjc,项目名称:monobjc-samples,代码行数:30,代码来源:WhereIsMyMacAppDelegate.cs


示例20: MonitoringViewController

		public MonitoringViewController (IntPtr handle) : base (handle)
		{
			locationManger = new CLLocationManager ();
			numberFormatter = new NSNumberFormatter () {
				NumberStyle = NSNumberFormatterStyle.Decimal
			};
			uuid = Defaults.DefaultProximityUuid;
		}
开发者ID:Rajneesh360Logica,项目名称:monotouch-samples,代码行数:8,代码来源:MonitoringViewController.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CLocalization类代码示例发布时间:2022-05-24
下一篇:
C# CLLocationCoordinate2D类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap