public override void ViewDidLoad ()
 {
     base.ViewDidLoad ();
     
     _locations = LocationHelper.Instance.Locations;
     LocationHelper.Instance.LocationAdded += delegate { locationTable.ReloadData (); };
     
     startLocation.Clicked += delegate { 
         LocationHelper.Instance.StartLocationUpdates (); 
         
         // creating and arbitrary region for now
         // we'll make this interactive when we introduce mapkit in the next chapter
         _testRegion = new CLRegion (new CLLocationCoordinate2D (41.79554472, -72.62135916), 1000, "testRegion");
         LocationHelper.Instance.StartRegionUpdates (_testRegion);
     };
     
     stopLocation.Clicked += delegate { 
         LocationHelper.Instance.StopLocationUpdates ();
         
         LocationHelper.Instance.StartRegionUpdates (_testRegion);
     };
     
     _source = new LocationTableSource (this);
     locationTable.Source = _source;
 }
Exemplo n.º 2
0
        /// <summary>
        /// 領域から出た際にステータスを更新します。
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="region"></param>
        public override void RegionLeft(CLLocationManager manager, CLRegion region)
        {
            Console.WriteLine("Exit [{0}] Region", region.Identifier);
            var adapter = new DbAdapter_iOS();

            if (region.Identifier.Equals(RegionList.研究室.Identifier))
            {
                //研究室領域から退出
                UpdateStatus(Status.学内.GetStatusId());
                adapter.AddDeviceLog("在室状況を「学内」に更新", $"領域[{RegionList.研究室.Name}]から退出");
            }
            else
            {
                //学内領域から退出
                var gregion = RegionList.CampusAllRegions
                              .Where(r => r.Identifier.Equals(region.Identifier))
                              .First();
                adapter.UpdateGeofenceStatus(UserDataModel.Instance.DeviceId, gregion.DbIdentifierName, false);

                adapter.AddDeviceLog($"領域[{gregion.Name}]から退出");

                if (manager.Location != null)
                {
                    AddLocationLog(manager.Location, "LastUpdate", false);
                }
                else
                {
                    manager.RequestLocation();
                }
            }
        }
Exemplo n.º 3
0
 void RegionEntered(CLRegion region)
 {
     if (OnRegionEnteredDelegate != null)
     {
         OnRegionEnteredDelegate(region.Identifier);
     }
 }
        void OnRegionLeft(CLRegion region)
        {
            if (!mGeofenceResults.ContainsKey(region.Identifier))
            {
                mGeofenceResults.Add(region.Identifier, new GeofenceResult()
                {
                    RegionId = region.Identifier
                });
            }

            if (LastKnownLocation != null)
            {
                mGeofenceResults[region.Identifier].Latitude  = LastKnownLocation.Latitude;
                mGeofenceResults[region.Identifier].Longitude = LastKnownLocation.Longitude;
                mGeofenceResults[region.Identifier].Accuracy  = LastKnownLocation.Accuracy;
            }
            else
            {
                mGeofenceResults[region.Identifier].Latitude  = region.Center.Latitude;
                mGeofenceResults[region.Identifier].Longitude = region.Center.Longitude;
                mGeofenceResults[region.Identifier].Accuracy  = region.Radius;
            }

            mGeofenceResults[region.Identifier].LastExitTime = DateTime.Now;
            mGeofenceResults[region.Identifier].Transition   = GeofenceTransition.Exited;

            CrossGeofence.GeofenceListener.OnRegionStateChanged(mGeofenceResults[region.Identifier]);

            if (Regions.ContainsKey(region.Identifier) && Regions[region.Identifier].ShowNotification && Regions[region.Identifier].ShowExitNotification)
            {
                CreateNotification(ViewAction, string.IsNullOrEmpty(Regions[region.Identifier].NotificationExitMessage) ? GeofenceResults[region.Identifier].ToString() : Regions[region.Identifier].NotificationExitMessage);
            }
        }
        void AddRegion(GeofenceCircularRegion region)
        {
            CLRegion cRegion = null;


            if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
            {
                cRegion = new CLCircularRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
            }
            else
            {
                cRegion = new CLRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
            }


            cRegion.NotifyOnEntry = region.NotifyOnEntry || region.NotifyOnStay;
            cRegion.NotifyOnExit  = region.NotifyOnExit;


            locationManager.StartMonitoring(cRegion);

            // Request state for this region, putting request behind a timer per thread: http://stackoverflow.com/questions/24543814/diddeterminestate-not-always-called
            Task.Run(async() => {
                await Task.Delay(TimeSpan.FromSeconds(2));
                locationManager.RequestState(cRegion);
            });
        }
 public void StartRegionUpdates(CLRegion region)
 {
     if (CLLocationManager.RegionMonitoringAvailable && CLLocationManager.RegionMonitoringEnabled)
     {
         _locationManager.StartMonitoring(region, CLLocation.AccuracyHundredMeters);
     }
 }
Exemplo n.º 7
0
        async void Broadcast(CLLocationManager manager, CLRegion region, GeofenceState status)
        {
            try
            {
                if (region is CLCircularRegion native)
                {
                    var geofence = await this.repository.Get(native.Identifier);

                    if (geofence != null)
                    {
                        this.gdelegate.OnStatusChanged(status, geofence);
                        if (geofence.SingleUse)
                        {
                            await this.repository.Remove(geofence.Identifier);

                            manager.StopMonitoring(native);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 領域に侵入した際にステータスを更新します。
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="region"></param>
        public override void RegionEntered(CLLocationManager manager, CLRegion region)
        {
            var adapter = new DbAdapter_iOS();

            if (region.Identifier.Equals(RegionList.研究室.Identifier))
            {
                //研究室領域に侵入
                UpdateStatus(Status.在室.GetStatusId());
                adapter.AddDeviceLog("在室状況を「在室」に更新", $"領域[{RegionList.研究室.Name}]に侵入");
            }
            else
            {
                //学内領域に侵入
                var gregion = RegionList.CampusAllRegions
                              .Where(r => r.Identifier.Equals(region.Identifier))
                              .First();

                adapter.UpdateGeofenceStatus(UserDataModel.Instance.DeviceId, gregion.DbIdentifierName, true);
                adapter.AddDeviceLog("ジオフェンス状態を更新", $"領域[{gregion.Name}]に侵入");

                if (manager.Location != null)
                {
                    AddLocationLog(manager.Location, "LastUpdate", true);
                }
                else
                {
                    manager.RequestLocation();
                }
            }
        }
Exemplo n.º 9
0
 void RegionExited(CLRegion region, bool outsideAllRegions)
 {
     if (OnRegionExitedDelegate != null)
     {
         OnRegionExitedDelegate(region.Identifier, outsideAllRegions);
     }
 }
Exemplo n.º 10
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _locations = LocationHelper.Instance.Locations;
            LocationHelper.Instance.LocationAdded += delegate { locationTable.ReloadData(); };

            startLocation.Clicked += delegate {
                LocationHelper.Instance.StartLocationUpdates();

                // creating and arbitrary region for now
                // we'll make this interactive when we introduce mapkit in the next chapter
                _testRegion = new CLRegion(new CLLocationCoordinate2D(41.79554472, -72.62135916), 1000, "testRegion");
                LocationHelper.Instance.StartRegionUpdates(_testRegion);
            };

            stopLocation.Clicked += delegate {
                LocationHelper.Instance.StopLocationUpdates();

                LocationHelper.Instance.StartRegionUpdates(_testRegion);
            };

            _source = new LocationTableSource(this);
            locationTable.Source = _source;
        }
        //Calls to Services to get content
        public BeaconContent GetEnterRegionContent(CLRegion region)
        {
            /*
             *      If you have very few beacons per region and/or your
             *      content is now overly dynamic (i.e.: changed throughout the
             *      day, I recommend not caching (caveat: questionable connections)
             *
             *      As an alternative to pulling all beacon data for a given region,
             *      we could pull both the entry and exit region content upon
             *      entering a region
             */

            bool show = false;

            BeaconContent[] regions;

            regions = _testData.GetRegionContent();

            var reg = (from h in regions
                       where h.RegionEvent == CLRegionState.Inside && h.Region == region.Identifier.ToString()
                       select h).FirstOrDefault();

            if (reg != null)
            {
                show = ShouldShowContent(reg.ContentId);
            }

            return((show) ? reg as BeaconContent : null);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Get called when Region is left
        /// </summary>
        /// <param name="region">Region thats left.</param>
        private void OnRegionLeft(CLRegion region)
        {
            if (!this.geofenceResults.ContainsKey(region.Identifier))
            {
                this.geofenceResults.Add(
                    region.Identifier,
                    new GeofenceResult
                {
                    RegionId = region.Identifier
                });
            }

            if (this.LastKnownLocation != null)
            {
                this.geofenceResults[region.Identifier].Latitude  = this.LastKnownLocation.Latitude;
                this.geofenceResults[region.Identifier].Longitude = this.LastKnownLocation.Longitude;
                this.geofenceResults[region.Identifier].Accuracy  = this.LastKnownLocation.Accuracy;
            }
            else
            {
                this.geofenceResults[region.Identifier].Latitude  = region.Center.Latitude;
                this.geofenceResults[region.Identifier].Longitude = region.Center.Longitude;
                this.geofenceResults[region.Identifier].Accuracy  = region.Radius;
            }

            this.geofenceResults[region.Identifier].LastExitTime = DateTime.Now;
            this.geofenceResults[region.Identifier].Transition   = GeofenceTransition.Exited;

            CrossGeofence.GeofenceListener.OnRegionStateChanged(this.geofenceResults[region.Identifier]);

            if (this.Regions[region.Identifier].ShowNotification)
            {
                GeofenceImplementation.CreateNotification(ViewAction, string.IsNullOrEmpty(this.Regions[region.Identifier].NotificationExitMessage) ? this.GeofenceResults[region.Identifier].ToString() : this.Regions[region.Identifier].NotificationExitMessage);
            }
        }
Exemplo n.º 13
0
        async void Broadcast(CLRegion region, GeofenceState status)
        {
            try
            {
                if (region is CLCircularRegion native)
                {
                    var repo     = ShinyHost.Resolve <IRepository>().Wrap();
                    var geofence = await repo.Get(native.Identifier);

                    if (geofence != null)
                    {
                        ShinyHost.Resolve <IGeofenceDelegate>().OnStatusChanged(status, geofence);

                        if (geofence.SingleUse)
                        {
                            await ShinyHost.Resolve <IGeofenceManager>().StopMonitoring(geofence);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
Exemplo n.º 14
0
        internal void AddRegion(CLRegion region)
        {
#if __IOS__
            _locationManager.StartMonitoring(region, CLLocation.AccuracyBest);
#else
            _locationManager.StartMonitoring(region);
#endif
            Status = GeofenceMonitorStatus.Ready;
        }
Exemplo n.º 15
0
        void MonitorCurrentRegion(double lat, double lon, double radius, string identifier)
        {
            CLRegion region = new CLRegion(new CLLocationCoordinate2D(lat, lon), radius, identifier);

            region.NotifyOnExit  = true;
            region.NotifyOnEntry = false;

            _clManager.StartMonitoring(region);
        }
 /// <summary>
 /// Converts a <see cref="CLRegion"/> to a <see cref="GeoRegion"/>.
 /// </summary>
 /// <param name="region">The region.</param>
 /// <returns>The converted value.</returns>
 public static GeoRegion ToGeoRegion(this CLRegion region) =>
 new GeoRegion
 {
     Identifier    = region.Identifier,
     Center        = region.Center.ToLocation(),
     Radius        = region.Radius,
     NotifyOnEntry = region.NotifyOnEntry,
     NotifyOnExit  = region.NotifyOnExit
 };
        // When Beacon enter the region created in StartMonitoring()
        public override void RegionEntered(CLLocationManager manager, CLRegion region)
        {
            base.RegionEntered(manager, region);

            if (region is CLBeaconRegion)
            {
                // Start ranging only if the feature is available and isRangingActive is set to true
                if (CLLocationManager.IsRangingAvailable && isRangingActive)
                {
                    manager.StartRangingBeacons((CLBeaconRegion)region);
                }
            }
        }
Exemplo n.º 18
0
        void OnRegionEntered(CLRegion region)
        {
            if (GeofenceResults.ContainsKey(region.Identifier) && GeofenceResults[region.Identifier].Transition == GeofenceTransition.Entered)
            {
                return;
            }

            if (!mGeofenceResults.ContainsKey(region.Identifier))
            {
                mGeofenceResults.Add(region.Identifier, new GeofenceResult()
                {
                    RegionId = region.Identifier
                });
            }

            if (LastKnownLocation != null)
            {
                mGeofenceResults[region.Identifier].Latitude  = LastKnownLocation.Latitude;
                mGeofenceResults[region.Identifier].Longitude = LastKnownLocation.Longitude;
                mGeofenceResults[region.Identifier].Accuracy  = LastKnownLocation.Accuracy;
            }
            else
            {
                mGeofenceResults[region.Identifier].Latitude  = region.Center.Latitude;
                mGeofenceResults[region.Identifier].Longitude = region.Center.Longitude;
                mGeofenceResults[region.Identifier].Accuracy  = region.Radius;
            }

            mGeofenceResults[region.Identifier].LastEnterTime = DateTime.Now;
            mGeofenceResults[region.Identifier].LastExitTime  = null;
            mGeofenceResults[region.Identifier].Transition    = GeofenceTransition.Entered;
            if (mRegions.ContainsKey(region.Identifier))
            {
                region.NotifyOnEntry = mRegions[region.Identifier].NotifyOnEntry;
            }
            if (region.NotifyOnEntry)
            {
                CrossGeofence.GeofenceListener.OnRegionStateChanged(mGeofenceResults[region.Identifier]);

                if (Regions.ContainsKey(region.Identifier) && Regions[region.Identifier].ShowNotification && Regions[region.Identifier].ShowEntryNotification)
                {
                    CreateNotification(ViewAction, string.IsNullOrEmpty(Regions[region.Identifier].NotificationEntryMessage) ? GeofenceResults[region.Identifier].ToString() : Regions[region.Identifier].NotificationEntryMessage);
                }
            }

            Task.Factory.StartNew(async() =>
            {
                //Checks if device has stayed asynchronously
                await CheckIfStayed(region.Identifier);
            });
        }
Exemplo n.º 19
0
        void HandleRegionExited(CLRegion region)
        {
            Console.WriteLine("LocationManager: HandleRegionExited");

            // find this region in our list and set the "InRegion" to false
            bool wasInRegion = false;

            foreach (TrackedRegion trackedRegion in Regions)
            {
                if (trackedRegion.Region.Identifier == region.Identifier)
                {
                    if (trackedRegion.InRegion == true)
                    {
                        wasInRegion = true;
                    }
                    trackedRegion.InRegion = false;

                    // also, if we're in the landmark owned by this region, clear it.
                    if (trackedRegion.LandmarkInRegion(CurrentLandMark))
                    {
                        CurrentLandMark = null;
                    }
                }
            }

            // stop intense scanning if we leave ALL tracked regions.
            bool outsideAllRegions = true;

            foreach (TrackedRegion trackedRegion in Regions)
            {
                // if we find at least one region still being tracked, don't stop scanning.
                if (trackedRegion.InRegion == true)
                {
                    outsideAllRegions = false;
                    break;
                }
            }

            // Invoke callback
            if (wasInRegion)
            {
                // if now outside all regions, stop intense scanning
                if (outsideAllRegions)
                {
                    StopIntenseLocationScanning( );
                }

                ExitedRegion(region, outsideAllRegions);
            }
        }
Exemplo n.º 20
0
            public override void RegionEntered(CLLocationManager manager, CLRegion region)
            {
                UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert, (arg1, arg2) => { });
                var notification = new UNMutableNotificationContent {
                    Title    = "Region entered",
                    Subtitle = "Something This Way Comes",
                    Body     = "I need to tell you something, but first read this."
                };

                var notificationTrigger = UNTimeIntervalNotificationTrigger.CreateTrigger(5, false);
                var request             = UNNotificationRequest.FromIdentifier("notification1", notification, notificationTrigger);

                UNUserNotificationCenter.Current.AddNotificationRequest(request, null);
            }
        private CLRegion GetRegion(string identifier)
        {
            CLRegion region = null;

            foreach (CLRegion r in locationManager.MonitoredRegions)
            {
                if (r.Identifier.Equals(identifier, StringComparison.Ordinal))
                {
                    region = r;
                    break;
                }
            }
            return(region);
        }
        // When a Beacon exit the region created in MonitorBeacons()
        public override void RegionLeft(CLLocationManager manager, CLRegion region)
        {
            base.RegionLeft(manager, region);

            if (region is CLBeaconRegion)
            {
                // Start ranging only if the feature is available.
                if (CLLocationManager.IsRangingAvailable && isRangingActive)
                {
                    // TODO: Ver qué hace realmente este Stop
                    ///////////////manager.StopRangingBeacons((CLBeaconRegion)region);
                }
            }
        }
Exemplo n.º 23
0
 async void Invoke(CLRegion region, BeaconRegionState status)
 {
     if (region is CLBeaconRegion native)
     {
         var beaconRegion = new BeaconRegion(
             native.Identifier,
             native.ProximityUuid.ToGuid(),
             native.Major?.UInt16Value,
             native.Minor?.UInt16Value
             );
         await this.services.RunDelegates <IBeaconMonitorDelegate>(
             x => x.OnStatusChanged(status, beaconRegion)
             );
     }
 }
Exemplo n.º 24
0
        /// <summary>
        /// Get Called on RegionEntered.
        /// </summary>
        /// <param name="region">Region entered.</param>
        private async void OnRegionEntered(CLRegion region)
        {
            if (this.GeofenceResults.ContainsKey(region.Identifier) && this.GeofenceResults[region.Identifier].Transition == GeofenceTransition.Entered)
            {
                return;
            }

            if (!this.geofenceResults.ContainsKey(region.Identifier))
            {
                this.geofenceResults.Add(
                    region.Identifier,
                    new GeofenceResult
                {
                    RegionId = region.Identifier
                });
            }

            if (this.LastKnownLocation != null)
            {
                this.geofenceResults[region.Identifier].Latitude  = this.LastKnownLocation.Latitude;
                this.geofenceResults[region.Identifier].Longitude = this.LastKnownLocation.Longitude;
                this.geofenceResults[region.Identifier].Accuracy  = this.LastKnownLocation.Accuracy;
            }
            else
            {
                this.geofenceResults[region.Identifier].Latitude  = region.Center.Latitude;
                this.geofenceResults[region.Identifier].Longitude = region.Center.Longitude;
                this.geofenceResults[region.Identifier].Accuracy  = region.Radius;
            }

            this.geofenceResults[region.Identifier].LastEnterTime = DateTime.Now;
            this.geofenceResults[region.Identifier].LastExitTime  = null;
            this.geofenceResults[region.Identifier].Transition    = GeofenceTransition.Entered;

            if (region.NotifyOnEntry)
            {
                CrossGeofence.GeofenceListener.OnRegionStateChanged(this.geofenceResults[region.Identifier]);

                if (this.Regions.ContainsKey(region.Identifier) && this.Regions[region.Identifier].ShowNotification)
                {
                    GeofenceImplementation.CreateNotification(ViewAction, string.IsNullOrEmpty(this.Regions[region.Identifier].NotificationEntryMessage) ? this.GeofenceResults[region.Identifier].ToString() : this.Regions[region.Identifier].NotificationEntryMessage);
                }
            }

            // Checks if device has stayed asynchronously
            await GeofenceImplementation.CheckIfStayed(region.Identifier);
        }
            public override void MonitoringFailed(CLLocationManager manager, CLRegion region, NSError error)
            {
                Console.WriteLine("region monitoring failed for region {0}", region.Identifier);

                if (error.Code == (int)CLError.RegionMonitoringDenied)
                {
                    Console.WriteLine("RegionMonitoringDenied");
                }
                else if (error.Code == (int)CLError.RegionMonitoringFailure)
                {
                    Console.WriteLine("RegionMonitoringFailure");
                }
                else if (error.Code == (int)CLError.RegionMonitoringSetupDelayed)
                {
                    Console.WriteLine("RegionMonitoringSetupDelayed");
                }
            }
Exemplo n.º 26
0
        public override void RegionLeft(CLLocationManager manager, CLRegion region)
        {
            BeaconDevice beacon;

            lock (_sync) {
                beacon = _beacons.FirstOrDefault(b => b.DeviceId == region.Identifier);
            }

            System.Diagnostics.Debug.WriteLine("Left " + region);

            if (beacon != null)
            {
                Left(this, new BeaconEventArgs {
                    BeaconDevice = beacon
                });
            }
        }
Exemplo n.º 27
0
        public bool StartRegionUpdates(CLRegion region)
        {
            bool result = false;

            // Чтобы следить за пересечением границ облостей необходимо узнать:
            // поддерживает ли телефон слежение за областями
            // разрешено ли данному приложения следить за облостями
            if (CLLocationManager.RegionMonitoringAvailable &&
                CLLocationManager.Status == CLAuthorizationStatus.Authorized
                )
            {
                _locationManager.StartMonitoring(region);
                result = true;
            }

            return(result);
        }
Exemplo n.º 28
0
            public bool LandmarkInRegion(CLRegion landmark)
            {
                // it's possible they'll offer null. Ignore that.
                if (landmark != null)
                {
                    foreach (CLRegion currLandmark in LandMarks)
                    {
                        // if we match the lat AND long, its safe to assume this is the landmark.
                        if (currLandmark.Center.Latitude == landmark.Center.Latitude &&
                            currLandmark.Center.Longitude == landmark.Center.Longitude)
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
Exemplo n.º 29
0
        async void Broadcast(CLLocationManager manager, CLRegion region, GeofenceState status)
        {
            if (region is CLCircularRegion native)
            {
                var geofence = await this.repository.Get(native.Identifier);

                if (geofence != null)
                {
                    await this.delegates.Value.RunDelegates(x => x.OnStatusChanged(status, geofence));

                    if (geofence.SingleUse)
                    {
                        await this.repository.Remove(geofence.Identifier);

                        manager.StopMonitoring(native);
                    }
                }
            }
        }
Exemplo n.º 30
0
        void HandleRegionEntered(CLRegion region)
        {
            Console.WriteLine("LocationManager: HandleRegionEntered");

            // find this region in our list and set the "InRegion" to true
            foreach (TrackedRegion trackedRegion in Regions)
            {
                if (trackedRegion.Region.Identifier == region.Identifier)
                {
                    trackedRegion.InRegion = true;
                }
            }

            // Start intense scanning
            StartIntenseLocationScanning( );

            // Invoke callback
            EnteredRegion(region);
        }
Exemplo n.º 31
0
        /// <summary>
        /// Этот метод можно вызывать если известно что пользователь разрешил определение его местоположения
        /// </summary>
        private void StartRegionUpdates()
        {
            // работа
            CLLocationCoordinate2D workCenter = new CLLocationCoordinate2D(59.938396, 30.264938);

            // Кировский завод
            CLLocationCoordinate2D homeCenter = new CLLocationCoordinate2D(59.875316, 30.267856);

            CLRegion[] regions = new CLRegion[]
            {
                new CLRegion(workCenter, 100, "work100"),
                new CLRegion(workCenter, 200, "work200"),
                new CLRegion(workCenter, 300, "work300"),
                new CLRegion(workCenter, 400, "work400"),
                new CLRegion(workCenter, 500, "work500"),
                new CLRegion(workCenter, 600, "work600"),
                new CLRegion(workCenter, 700, "work700"),
                new CLRegion(workCenter, 800, "work800"),
                new CLRegion(workCenter, 900, "work900"),
                new CLRegion(workCenter, 1000, "work1000"),

                // дом
                new CLRegion(homeCenter, 100, "home100"),
                new CLRegion(homeCenter, 200, "home200"),
                new CLRegion(homeCenter, 300, "home300"),
                new CLRegion(homeCenter, 400, "home400"),
                new CLRegion(homeCenter, 500, "home500"),
                new CLRegion(homeCenter, 600, "home600"),
                new CLRegion(homeCenter, 700, "home700"),
                new CLRegion(homeCenter, 800, "home800"),
                new CLRegion(homeCenter, 900, "home900"),
                new CLRegion(homeCenter, 1000, "home1000")
            };
            // работа

            foreach (CLRegion r in regions)
            {
                _locationHelper.StartRegionUpdates(r);
                _locationHelper.LocationObjects.Insert(0, string.Format("start region updates: {0}", r.Identifier));
                _locationHelper.RaiseLocationObjectAdded();
            }
        }
 public override void MonitoringFailed(CLLocationManager manager, CLRegion region, NSError error)
 {
     _owner.SendError (ToMvxLocationErrorCode (manager, error, region));
 }
Exemplo n.º 33
0
 public override void MonitoringFailed(CLLocationManager manager, CLRegion region, MonoTouch.Foundation.NSError error)
 {
     _locationHelper.LocationObjects.Insert(0, string.Format("MonitoringFailed: {0}", region.Identifier));
     NotifyUser("MonitoringFailed", region.Identifier);
 }
 public void StopRegionUpdates (CLRegion region)
 {
     _locationManager.StopMonitoring (region);
 }
            public override void MonitoringFailed(CLLocationManager manager, CLRegion region, NSError error)
            {
#warning TODO!
                //base.MonitoringFailed(manager, region, error);
            }
		public void StopMonitoring (CLRegion clCircularRegion)
		{
			_clLocationManager.StopMonitoring (clCircularRegion);
		}
      void AddRegion(GeofenceCircularRegion region)
      {
          CLRegion cRegion = null;


          if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
          {
              cRegion = new CLCircularRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
          }
          else
          {
              cRegion = new CLRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
          }


          cRegion.NotifyOnEntry = region.NotifyOnEntry || region.NotifyOnStay;
          cRegion.NotifyOnExit = region.NotifyOnExit;



          locationManager.StartMonitoring(cRegion);
          locationManager.RequestState(cRegion);
      }
Exemplo n.º 38
0
        public bool StartRegionUpdates(CLRegion region)
        {
            bool result = false;

            // Чтобы следить за пересечением границ облостей необходимо узнать:
            // поддерживает ли телефон слежение за областями
            // разрешено ли данному приложения следить за облостями
            if (   CLLocationManager.RegionMonitoringAvailable
                && CLLocationManager.Status == CLAuthorizationStatus.Authorized
                )
            {
                _locationManager.StartMonitoring(region);
                result = true;
            }

            return result;
        }
 public void StartRegionUpdates (CLRegion region)
 {        
     if (CLLocationManager.RegionMonitoringAvailable && CLLocationManager.RegionMonitoringEnabled) {
         _locationManager.StartMonitoring (region, CLLocation.AccuracyHundredMeters);
     }
 }
      void OnRegionEntered(CLRegion region)
      {
          if (GeofenceResults.ContainsKey(region.Identifier) && GeofenceResults[region.Identifier].Transition == GeofenceTransition.Entered)
          {
              return;
          }

          if (!mGeofenceResults.ContainsKey(region.Identifier))
          {
              mGeofenceResults.Add(region.Identifier, new GeofenceResult()
              {
                  RegionId = region.Identifier
              });
          }

          if (LastKnownLocation != null)
          {
              mGeofenceResults[region.Identifier].Latitude = LastKnownLocation.Latitude;
              mGeofenceResults[region.Identifier].Longitude = LastKnownLocation.Longitude;
              mGeofenceResults[region.Identifier].Accuracy = LastKnownLocation.Accuracy;
          }
          else
          {
              mGeofenceResults[region.Identifier].Latitude = region.Center.Latitude;
              mGeofenceResults[region.Identifier].Longitude = region.Center.Longitude;
              mGeofenceResults[region.Identifier].Accuracy = region.Radius;
          }
     
          mGeofenceResults[region.Identifier].LastEnterTime = DateTime.Now;
          mGeofenceResults[region.Identifier].LastExitTime = null;
          mGeofenceResults[region.Identifier].Transition = GeofenceTransition.Entered;
          if(region.NotifyOnEntry)
          {
              CrossGeofence.GeofenceListener.OnRegionStateChanged(mGeofenceResults[region.Identifier]);

              if (Regions.ContainsKey(region.Identifier) && Regions[region.Identifier].ShowNotification)
              {
                  CreateNotification(ViewAction, string.IsNullOrEmpty(Regions[region.Identifier].NotificationEntryMessage) ? GeofenceResults[region.Identifier].ToString() : Regions[region.Identifier].NotificationEntryMessage);
              }

          }


          //Checks if device has stayed asynchronously
          CheckIfStayed(region.Identifier);

        
      }
      void OnRegionLeft(CLRegion region)
      {
          if (!mGeofenceResults.ContainsKey(region.Identifier))
          {
              mGeofenceResults.Add(region.Identifier, new GeofenceResult()
              {
                  RegionId = region.Identifier
              });
          }

          if(LastKnownLocation!=null)
          {
              mGeofenceResults[region.Identifier].Latitude = LastKnownLocation.Latitude;
              mGeofenceResults[region.Identifier].Longitude = LastKnownLocation.Longitude;
              mGeofenceResults[region.Identifier].Accuracy = LastKnownLocation.Accuracy;
          }
          else
          {
              mGeofenceResults[region.Identifier].Latitude = region.Center.Latitude;
              mGeofenceResults[region.Identifier].Longitude = region.Center.Longitude;
              mGeofenceResults[region.Identifier].Accuracy = region.Radius;
          }
        
          mGeofenceResults[region.Identifier].LastExitTime = DateTime.Now;
          mGeofenceResults[region.Identifier].Transition = GeofenceTransition.Exited;
         
          CrossGeofence.GeofenceListener.OnRegionStateChanged(mGeofenceResults[region.Identifier]);

          if (Regions[region.Identifier].ShowNotification)
          {
              CreateNotification(ViewAction, string.IsNullOrEmpty(Regions[region.Identifier].NotificationExitMessage) ? GeofenceResults[region.Identifier].ToString() : Regions[region.Identifier].NotificationExitMessage);
          }
      }
Exemplo n.º 42
0
        /// <summary>
        /// Get Called on RegionEntered.
        /// </summary>
        /// <param name="region">Region entered.</param>
        private async void OnRegionEntered(CLRegion region)
        {
            if (this.GeofenceResults.ContainsKey(region.Identifier) && this.GeofenceResults[region.Identifier].Transition == GeofenceTransition.Entered)
            {
                return;
            }

            if (!this.geofenceResults.ContainsKey(region.Identifier))
            {
                this.geofenceResults.Add(
                    region.Identifier,
                    new GeofenceResult
                    {
                        RegionId = region.Identifier
                    });
            }

            if (this.LastKnownLocation != null)
            {
                this.geofenceResults[region.Identifier].Latitude = this.LastKnownLocation.Latitude;
                this.geofenceResults[region.Identifier].Longitude = this.LastKnownLocation.Longitude;
                this.geofenceResults[region.Identifier].Accuracy = this.LastKnownLocation.Accuracy;
            }
            else
            {
                this.geofenceResults[region.Identifier].Latitude = region.Center.Latitude;
                this.geofenceResults[region.Identifier].Longitude = region.Center.Longitude;
                this.geofenceResults[region.Identifier].Accuracy = region.Radius;
            }

            this.geofenceResults[region.Identifier].LastEnterTime = DateTime.Now;
            this.geofenceResults[region.Identifier].LastExitTime = null;
            this.geofenceResults[region.Identifier].Transition = GeofenceTransition.Entered;

            if (region.NotifyOnEntry)
            {
                CrossGeofence.GeofenceListener.OnRegionStateChanged(this.geofenceResults[region.Identifier]);

                if (this.Regions.ContainsKey(region.Identifier) && this.Regions[region.Identifier].ShowNotification)
                {
                    GeofenceImplementation.CreateNotification(ViewAction, string.IsNullOrEmpty(this.Regions[region.Identifier].NotificationEntryMessage) ? this.GeofenceResults[region.Identifier].ToString() : this.Regions[region.Identifier].NotificationEntryMessage);
                }
            }

            // Checks if device has stayed asynchronously
            await GeofenceImplementation.CheckIfStayed(region.Identifier);
        }
 public override void DidRangeBeaconsInRegion(NotificarePushLib library, NSArray beacons, CLRegion region)
 {
     Console.WriteLine ("Did range {0} beacons", beacons.Count);
 }
        void OnEnterRegion(CLRegion region)
        {
            if (EnterBeaconRegion != null)
            {
                var beaconRegion = region as CLBeaconRegion;

                if (beaconRegion != null)
                    EnterBeaconRegion(RegionBeaconConverter.ConvertRegionToBeacon(beaconRegion));
                else
                    throw new FormatException("Beacon has wrong format!");
            }
        }
 public override void MonitoringFailed(CLLocationManager manager, CLRegion region, NSError error)
 {
     // ignored for now
 }
      void AddRegion(GeofenceCircularRegion region)
      {
          CLRegion cRegion = null;


          if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
          {
              cRegion = new CLCircularRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
          }
          else
          {
              cRegion = new CLRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
          }


          cRegion.NotifyOnEntry = region.NotifyOnEntry || region.NotifyOnStay;
          cRegion.NotifyOnExit = region.NotifyOnExit;


          locationManager.StartMonitoring(cRegion);

          // Request state for this region, putting request behind a timer per thread: http://stackoverflow.com/questions/24543814/diddeterminestate-not-always-called
          Task.Run(async() => {
              await Task.Delay(TimeSpan.FromSeconds(2));
              locationManager.RequestState(cRegion);
          });
      }
Exemplo n.º 47
0
        /// <summary>
        /// Get called when Region is left
        /// </summary>
        /// <param name="region">Region thats left.</param>
        private void OnRegionLeft(CLRegion region)
        {
            if (!this.geofenceResults.ContainsKey(region.Identifier))
            {
                this.geofenceResults.Add(
                    region.Identifier, 
                    new GeofenceResult
                    {
                        RegionId = region.Identifier
                    });
            }

            if (this.LastKnownLocation != null)
            {
                this.geofenceResults[region.Identifier].Latitude = this.LastKnownLocation.Latitude;
                this.geofenceResults[region.Identifier].Longitude = this.LastKnownLocation.Longitude;
                this.geofenceResults[region.Identifier].Accuracy = this.LastKnownLocation.Accuracy;
            }
            else
            {
                this.geofenceResults[region.Identifier].Latitude = region.Center.Latitude;
                this.geofenceResults[region.Identifier].Longitude = region.Center.Longitude;
                this.geofenceResults[region.Identifier].Accuracy = region.Radius;
            }

            this.geofenceResults[region.Identifier].LastExitTime = DateTime.Now;
            this.geofenceResults[region.Identifier].Transition = GeofenceTransition.Exited;

            CrossGeofence.GeofenceListener.OnRegionStateChanged(this.geofenceResults[region.Identifier]);

            if (this.Regions[region.Identifier].ShowNotification)
            {
                GeofenceImplementation.CreateNotification(ViewAction, string.IsNullOrEmpty(this.Regions[region.Identifier].NotificationExitMessage) ? this.GeofenceResults[region.Identifier].ToString() : this.Regions[region.Identifier].NotificationExitMessage);
            }
        }
 public void StopMonitoring(CLRegion clCircularRegion)
 {
     var list = (List<string>)MonitoredRegionsRemoved;
     list.Add (clCircularRegion.Identifier);
 }
Exemplo n.º 49
0
		public override void RegionLeft (CLLocationManager manager, CLRegion region)
		{
			BeaconDevice beacon;
			lock (_sync) {
				beacon = _beacons.FirstOrDefault (b => b.DeviceId == region.Identifier);
			}
				
			System.Diagnostics.Debug.WriteLine ("Left " + region);

			if (beacon != null)
				Left (this, new BeaconEventArgs { BeaconDevice = beacon });
		}
            private MvxLocationErrorCode ToMvxLocationErrorCode (CLLocationManager manager, NSError error, CLRegion region = null)
            {
                var errorType = (CLError)(int)error.Code;

                if (errorType == CLError.Denied) {
                    return MvxLocationErrorCode.PermissionDenied;
                }

                if (errorType == CLError.Network) {
                    return MvxLocationErrorCode.Network;
                }

                if (errorType == CLError.DeferredCanceled) {
                    return MvxLocationErrorCode.Canceled;
                }

                return MvxLocationErrorCode.ServiceUnavailable;
            }
Exemplo n.º 51
0
        /// <summary>
        /// Этот метод можно вызывать если известно что пользователь разрешил определение его местоположения
        /// </summary>
        private void StartRegionUpdates()
        {
            // работа
            CLLocationCoordinate2D workCenter = new CLLocationCoordinate2D(59.938396,30.264938);

            // Кировский завод
            CLLocationCoordinate2D homeCenter = new CLLocationCoordinate2D(59.875316,30.267856);

            CLRegion[] regions = new CLRegion[]
            {
                new CLRegion(workCenter, 100,  "work100"),
                new CLRegion(workCenter, 200,  "work200"),
                new CLRegion(workCenter, 300,  "work300"),
                new CLRegion(workCenter, 400,  "work400"),
                new CLRegion(workCenter, 500,  "work500"),
                new CLRegion(workCenter, 600,  "work600"),
                new CLRegion(workCenter, 700,  "work700"),
                new CLRegion(workCenter, 800,  "work800"),
                new CLRegion(workCenter, 900,  "work900"),
                new CLRegion(workCenter, 1000, "work1000"),

                // дом
                new CLRegion(homeCenter, 100,  "home100"),
                new CLRegion(homeCenter, 200,  "home200"),
                new CLRegion(homeCenter, 300,  "home300"),
                new CLRegion(homeCenter, 400,  "home400"),
                new CLRegion(homeCenter, 500,  "home500"),
                new CLRegion(homeCenter, 600,  "home600"),
                new CLRegion(homeCenter, 700,  "home700"),
                new CLRegion(homeCenter, 800,  "home800"),
                new CLRegion(homeCenter, 900,  "home900"),
                new CLRegion(homeCenter, 1000, "home1000")
            };
            // работа

            foreach (CLRegion r in regions)
            {
                _locationHelper.StartRegionUpdates(r);
                _locationHelper.LocationObjects.Insert(0, string.Format("start region updates: {0}", r.Identifier));
                _locationHelper.RaiseLocationObjectAdded();
            }
        }
Exemplo n.º 52
0
 private Geofence(CLRegion region)
 {
     _region = region;
 }
 public override void RegionEntered (CLLocationManager manager, CLRegion region)
 {
     Console.WriteLine("entered region {0}", region.Identifier);
 }
Exemplo n.º 54
0
        /// <summary>
        /// Initializes a new Geofence object given the id and the shape of the geofence.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="geoshape"></param>
        public Geofence(string id, IGeoshape geoshape)
        {
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE
            _fence = new Windows.Devices.Geolocation.Geofencing.Geofence(id, (Windows.Devices.Geolocation.Geocircle)((Geocircle)geoshape));
#elif __UNIFIED__
            _shape = (Geocircle)geoshape;

            if(_shape.Radius > GeofenceMonitor.Current.maxRegion)
            {
                throw new PlatformNotSupportedException("Geofence Radius is greater than the maximum supported on this platform");
            }

            _region = new CLCircularRegion(new CLLocationCoordinate2D(_shape.Center.Latitude, _shape.Center.Longitude), _shape.Radius, id);
#else
                throw new PlatformNotSupportedException();
#endif
        }
 public override void MonitoringFailed (CLLocationManager manager, CLRegion region, NSError error)
 {
     Console.WriteLine ("region monitoring failed for region {0}", region.Identifier);
     
     if (error.Code == (int)CLError.RegionMonitoringDenied){
         Console.WriteLine("RegionMonitoringDenied");
     }
     else if(error.Code == (int)CLError.RegionMonitoringFailure){
         Console.WriteLine("RegionMonitoringFailure"); 
     }
     else if(error.Code == (int)CLError.RegionMonitoringSetupDelayed){
         Console.WriteLine("RegionMonitoringSetupDelayed"); 
     }
 }
Exemplo n.º 56
0
 public override void RegionLeft(CLLocationManager manager, CLRegion region)
 {
     _locationHelper.LocationObjects.Insert(0, string.Format("RegionLeft: {0}", region.Identifier));
     NotifyUser("RegionLeft", region.Identifier);
 }