Exemplo n.º 1
0
        public TrackedRegion(double latitude, double longitude, float radius, string description, LocationManagerService parentService)
        {
            Landmarks = new List <Android.Locations.Location>();

            Latitude  = latitude;
            Longitude = longitude;
            Radius    = radius;

            GeofenceBuilder geoBuilder = new Android.Gms.Location.GeofenceBuilder();

            // Set the request ID of the geofence. This is a string to identify this
            // geofence.
            geoBuilder.SetRequestId(description);

            // Set the circular region of this geofence.
            geoBuilder.SetCircularRegion(latitude, longitude, radius);

            // Set the expiration duration of the geofence. This geofence gets automatically
            // removed after this period of time.
            geoBuilder.SetExpirationDuration(Geofence.NeverExpire);

            // Set the transition types of interest. Alerts are only generated for these
            // transition. We track entry and exit transitions in this sample.
            geoBuilder.SetTransitionTypes(Geofence.GeofenceTransitionEnter | Geofence.GeofenceTransitionExit);

            Region = geoBuilder.Build( );

            InRegion = false;

            ParentService = parentService;

            // Monitor the geofence events, and wait 90 seconds to handle it, incase we get a false
            // positive (exit/enter when we're still in the region). This can happen due to cell-tower swapping,
            // wifi proximity, etc.
            GeofenceEventTimer           = new System.Timers.Timer();
            GeofenceEventTimer.AutoReset = false;
            GeofenceEventTimer.Interval  = LocationManagerService.GeofenceFilterTimer;
            GeofenceEventTimer.Elapsed  += (object sender, System.Timers.ElapsedEventArgs e) =>
            {
                Rock.Mobile.Util.Debug.WriteToLog(string.Format("Timer for region {0} TICK", Region.RequestId));

                Handler mainHandler = new Handler(ParentService.BaseContext.MainLooper);

                Action action = new Action(delegate
                {
                    ParentService.HandlePendingGeofencingEvent(PendingGeofenceEvent, this);
                });

                mainHandler.Post(action);
            };
        }
Exemplo n.º 2
0
 public LocationManagerBinder(LocationManagerService service)
 {
     Service = service;
 }