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


C# CLLocationManager.RequestState方法代码示例

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


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

示例1: GeofenceImplementation

      /// <summary>
      /// Geofence plugin iOS implementation
      /// </summary>
      public GeofenceImplementation()
      {

          mGeofenceResults = new Dictionary<string, GeofenceResult>();

          locationManager = new CLLocationManager();
          locationManager.DidStartMonitoringForRegion += DidStartMonitoringForRegion;
          locationManager.RegionEntered += RegionEntered;
          locationManager.RegionLeft +=RegionLeft;
          locationManager.Failed += OnFailure;
          locationManager.DidDetermineState += DidDetermineState;
          locationManager.LocationsUpdated += LocationsUpdated;
          string priorityType = "Balanced Power";
          switch(CrossGeofence.GeofencePriority)
          {
              case GeofencePriority.HighAccuracy:
                  priorityType = "High Accuracy";
                  locationManager.DesiredAccuracy = CLLocation.AccuracyBest;
                  break;
              case GeofencePriority.AcceptableAccuracy:
                  priorityType = "Acceptable Accuracy";
                  locationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters;
                  break;
              case GeofencePriority.MediumAccuracy:
                  priorityType = "Medium Accuracy";
                  locationManager.DesiredAccuracy = CLLocation.AccuracyHundredMeters;
                  break;
              case GeofencePriority.LowAccuracy:
                  priorityType = "Low Accuracy";
                  locationManager.DesiredAccuracy = CLLocation.AccuracyKilometer;
                  break;
              case GeofencePriority.LowestAccuracy:
                  priorityType = "Lowest Accuracy";
                  locationManager.DesiredAccuracy = CLLocation.AccuracyThreeKilometers;
                  break;
              default:
                  locationManager.DesiredAccuracy = CLLocation.AccurracyBestForNavigation;
                  break;
          }
          System.Diagnostics.Debug.WriteLine(string.Format("{0} - {1}: {2}", CrossGeofence.Id, "Location priority set to", priorityType));
    
          if(CrossGeofence.SmallestDisplacement>0)
          {
              locationManager.DistanceFilter = CrossGeofence.SmallestDisplacement;
              System.Diagnostics.Debug.WriteLine(string.Format("{0} - {1}: {2} meters", CrossGeofence.Id, "Location smallest displacement set to", CrossGeofence.SmallestDisplacement));
          }

         

          if (locationManager.MonitoredRegions.Count > 0 && IsMonitoring)
          {

              NSSet monitoredRegions = locationManager.MonitoredRegions;
             

              foreach (CLCircularRegion region in monitoredRegions)
              {
                  //If not on regions remove on startup since that region was set not persistent
                  if (!Regions.ContainsKey(region.Identifier))
                  {
                      locationManager.StopMonitoring(region);
                  }
                  else
                  {
                      locationManager.RequestState(region);
                  }
                 
              }

              locationManager.StartMonitoringSignificantLocationChanges();

              string message = string.Format("{0} - {1} {2} region(s)", CrossGeofence.Id, "Actually monitoring", locationManager.MonitoredRegions.Count);
              System.Diagnostics.Debug.WriteLine(message);
              
          }

          SetLastKnownLocation(locationManager.Location);
          
      }
开发者ID:lampshade9909,项目名称:xamarin-plugins,代码行数:82,代码来源:GeofenceImplementation.cs

示例2: ViewDidLoad

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

            CLCircularRegion region = new CLCircularRegion(new CLLocationCoordinate2D(10.009176843388, 76.3615990792536), 20.0, "Jubin's Desk");

            locLabel = (UILabel)this.View.ViewWithTag(2004);
            locLabel1 = (UILabel)this.View.ViewWithTag(2005);
            statusLabel = (UILabel)this.View.ViewWithTag(2006);
            locLabel.Text = "Location...";
            locManager = new CLLocationManager();
            locManager.RequestAlwaysAuthorization ();
            //locManager.RequestWhenInUseAuthorization ();
            locManager.DesiredAccuracy = CLLocation.AccuracyBest;
            //locManager.DistanceFilter = 5.0;
            locManager.UpdatedLocation+=(object sender, CLLocationUpdatedEventArgs e) => {
                locLabel.Text = "Longitude: "+e.NewLocation.Coordinate.Longitude+" Lattitude: "+e.NewLocation.Coordinate.Latitude;
                System.Diagnostics.Debug.WriteLine("Longitude: "+e.NewLocation.Coordinate.Longitude+" Lattitude: "+e.NewLocation.Coordinate.Latitude);
            };
            /* this gets fired and works fine */
            locManager.LocationsUpdated+=(object sender, CLLocationsUpdatedEventArgs e) => {
                foreach (CLLocation aLocation in e.Locations)
                {
                    locLabel1.Text = "Longitude: "+aLocation.Coordinate.Longitude.ToString()+" Lattitude: "+aLocation.Coordinate.Latitude.ToString();
                    if (region.ContainsCoordinate(new CLLocationCoordinate2D(aLocation.Coordinate.Latitude, aLocation.Coordinate.Longitude)))
                    {
                        statusLabel.Text = "Normal location update: cordinates inside the region";
                    }
                    else
                    {
                        statusLabel.Text = "Normal location update: cordinates outside the region";
                    }
                }
            };
            locManager.StartUpdatingLocation();

            if (CLLocationManager.IsMonitoringAvailable (typeof(CLCircularRegion)))
            {
                /* This doesn't get fired */
                locManager.DidDetermineState += (object sender, CLRegionStateDeterminedEventArgs e) => {
                    switch(e.State)
                    {
                        case CLRegionState.Inside:
                        InvokeOnMainThread(()=>{
                            locLabel.Text = "Iniside...";
                            UIAlertView testAlert = new UIAlertView ();
                            testAlert.AddButton ("OK");
                            testAlert.Title = "Entered";
                            testAlert.Message = "Region "+e.Region.ToString();
                            testAlert.Show();
                        });
                        break;

                        case CLRegionState.Outside:
                        InvokeOnMainThread(()=>{
                            locLabel.Text = "Outside...";
                            UIAlertView testAlert1 = new UIAlertView ();
                            testAlert1.AddButton ("OK");
                            testAlert1.Title = "Exit";
                            testAlert1.Message = "Region "+e.Region.ToString();
                            testAlert1.Show();
                        });
                        break;

                        case CLRegionState.Unknown:
                        InvokeOnMainThread(()=>{
                            locLabel.Text = "Unknown state for region...";
                        });
                        break;
                        default:
                        break;
                    }
                };
                /* This works and gets fired */
                locManager.DidStartMonitoringForRegion += (o, e) => {
                    InvokeOnMainThread(()=>{
                        locManager.RequestState(e.Region);
                        locLabel.Text = "Now monitoring region : "+ e.Region.ToString ();
                    });
                };
                /* This doesn't get fired */
                locManager.DidVisit+=(object sender, CLVisitedEventArgs e) => {
                    InvokeOnMainThread(()=>{
                        locLabel.Text = "Did visit region...";
                        UIAlertView testAlert = new UIAlertView ();
                        testAlert.AddButton ("OK");
                        testAlert.Title = "Visited";
                        testAlert.Message = "Region "+e.Visit.Coordinate.Latitude.ToString()+" | "+e.Visit.Coordinate.Longitude.ToString();
                        testAlert.Show();
                    });
                };
                /* This doesn't get fired */
                locManager.RegionEntered += (o, e) => {
                    InvokeOnMainThread(()=>{
                        UIAlertView testAlert = new UIAlertView ();
                        testAlert.AddButton ("OK");
                        testAlert.Title = "Entered";
                        testAlert.Message = "Region "+e.Region.ToString();
                        testAlert.Show();
                        locLabel.Text = "Entered: "+e.Region.ToString();
//.........这里部分代码省略.........
开发者ID:jubinpolackal,项目名称:GeoFenceSample,代码行数:101,代码来源:MainViewController.cs

示例3: startLookingForBeacons

        public bool startLookingForBeacons()
        {
            BeaconList.init ();
            Console.WriteLine ("create called");
            var beaconUUID = new NSUuid (uuid);
            var beaconRegion = new CLBeaconRegion (beaconUUID, beaconId);

            beaconRegion.NotifyEntryStateOnDisplay = true;
            beaconRegion.NotifyOnEntry = true;
            beaconRegion.NotifyOnExit = true;

            locationManager = new CLLocationManager ();

            locationManager.RequestWhenInUseAuthorization ();

            locationManager.DidStartMonitoringForRegion += (object sender, CLRegionEventArgs e) => {
                locationManager.RequestState (e.Region);
            };

            locationManager.RegionEntered += (object sender, CLRegionEventArgs e) => {
                if (e.Region.Identifier == beaconId) {
                    Console.WriteLine ("beacon region entered");
                }
            };

            locationManager.DidDetermineState += (object sender, CLRegionStateDeterminedEventArgs e) => {

                switch (e.State) {
                case CLRegionState.Inside:
                    Console.WriteLine ("region state inside");
                    break;
                case CLRegionState.Outside:
                    Console.WriteLine ("region state outside");
                    break;
                case CLRegionState.Unknown:
                default:
                    Console.WriteLine ("region state unknown");
                    break;
                }
            };

            locationManager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => {
                if (e.Beacons.Length > 0) {
                    List<BeaconModel> beacons = new List<BeaconModel> {};
                    for (int i = 0; i < e.Beacons.Length; i++)
                    {
                        CLBeacon beacon = e.Beacons [i];
                        string proximity = "";
                        var major = (int) beacon.Major;
                        var minor = (int) beacon.Minor;
                        var accuracy = beacon.Accuracy;
                        Console.WriteLine(beacon.Major.ToString() + " " + beacon.Minor.ToString() + " " + beacon.Accuracy.ToString() );

                        switch (beacon.Proximity) {
                        case CLProximity.Immediate:
                            proximity = "Immediate";
                            break;
                        case CLProximity.Near:
                            proximity = "Near";
                            break;
                        case CLProximity.Far:
                            proximity = "Far";
                            break;
                        case CLProximity.Unknown:
                            proximity = "Unknown";
                            break;
                        }
                        BeaconModel beaconModel = new BeaconModel()
                        {
                            Major = major,
                            Minor = minor,
                            Proximity = proximity,
                            Region = e.Region.ToString(),
                            Accuracy = accuracy
                        };

            //						EventHandler<BeaconTest.onResultEventArgs> handler = onResultEvent;
            //						if (handler != null)
            //						{
            //							handler(this, new BeaconTest.onResultEventArgs{result = message});
            //						}
                        beacons.Add(beaconModel);
                    }
                    BeaconList.nearbyBeacons = BeaconList.updateList(beacons, BeaconList.nearbyBeacons, _numberOfFailedIterationsToRemove: 10);
                    BeaconList.lastUpdated = (Int32)(DateTime.UtcNow.Subtract(new  DateTime(1970,1,1,0,0,0))).TotalSeconds;
                    BeaconList.beaconsUpdated.Invoke();
                }
            };

            locationManager.StartMonitoring (beaconRegion);
            locationManager.StartRangingBeacons (beaconRegion);
            return true;
        }
开发者ID:kcrandall,项目名称:BeaconTest,代码行数:93,代码来源:BeaconHandling_iOS.cs

示例4: ViewDidLoad

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

            var beaconUUID = new NSUuid (uuid);
            var beaconRegion = new CLBeaconRegion (beaconUUID, beaconId);

            beaconRegion.NotifyEntryStateOnDisplay = true;
            beaconRegion.NotifyOnEntry = true;
            beaconRegion.NotifyOnExit = true;

            locationManager = new CLLocationManager ();

            locationManager.RequestWhenInUseAuthorization ();

            locationManager.DidStartMonitoringForRegion += (object sender, CLRegionEventArgs e) => {
                locationManager.RequestState (e.Region);
            };

            locationManager.RegionEntered += (object sender, CLRegionEventArgs e) => {
                if (e.Region.Identifier == beaconId) {
                    Console.WriteLine ("beacon region entered");
                }
            };

            locationManager.DidDetermineState += (object sender, CLRegionStateDeterminedEventArgs e) => {

                switch (e.State) {
                case CLRegionState.Inside:
                    Console.WriteLine ("region state inside");
                    break;
                case CLRegionState.Outside:
                    Console.WriteLine ("region state outside");
                    break;
                case CLRegionState.Unknown:
                default:
                    Console.WriteLine ("region state unknown");
                    break;
                }
            };

            locationManager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => {
                if (e.Beacons.Length > 0) {

                    CLBeacon beacon = e.Beacons [0];

                    switch (beacon.Proximity) {
                    case CLProximity.Immediate:
                        message = "Immediate";
                        break;
                    case CLProximity.Near:
                        message = "Near";
                        break;
                    case CLProximity.Far:
                        message = "Far";
                        break;
                    case CLProximity.Unknown:
                        message = "Unknown";
                        break;
                    }

                    if (previousProximity != beacon.Proximity) {
                        Console.WriteLine (message);
                    }
                    previousProximity = beacon.Proximity;
                }
            };

            locationManager.StartMonitoring (beaconRegion);
            locationManager.StartRangingBeacons (beaconRegion);
        }
开发者ID:IanLeatherbury,项目名称:mini-hacks,代码行数:71,代码来源:iBeaconMiniHackViewController.cs


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