public void CommitRegionsForTrack( ) { // if we're connected to google services, update our regions. if (ILocationServiceApi.IsConnected) { Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::CommitRegionsForTrack - GooglePlay connected. Comitting regions.")); // make sure the user called 'BeginAddRegionsForTrack' if (CommitState == RegionCommitState.QueuingRegions) { // request their removal NOW (why not, might allow them to be done by the time the new ones are added) if (PendingRegionsForRemove.Count > 0) { Android.Gms.Common.Apis.IPendingResult iRemovePendingResult = LocationServices.GeofencingApi.RemoveGeofences(ILocationServiceApi, PendingRegionsForRemove); iRemovePendingResult.SetResultCallback(this); CommitState = RegionCommitState.Removing; } else { InternalCommitRegionsForTrack( ); } } } else { Rock.Mobile.Util.Debug.WriteToLog(string.Format("LocationManagerService::CommitRegionsForTrack - GooglePlay NOT CONNECTED. Queuing region commit, and connecting to GooglePlay.")); // otherwise, flag that we want to commit, and connect the service. PendingRegionCommitEvent = true; ILocationServiceApi.Connect( ); } }
void AddRegionsToApi( ) { // setup our Geofencing API. GeofencingRequest.Builder builder = new GeofencingRequest.Builder(); builder.SetInitialTrigger(GeofencingRequest.InitialTriggerEnter); // add each geofence to the Geofence API List <IGeofence> geoFences = new List <IGeofence>(); foreach (TrackedRegion region in Regions) { geoFences.Add(region.Region); } builder.AddGeofences(geoFences); GeofencingRequest geofenceRequest = builder.Build( ); // create the intent that should be launched when a geofence is triggered Intent intent = new Intent(this, typeof(LocationManagerService)); PendingIntent pendingIntent = PendingIntent.GetService(this, 0, intent, PendingIntentFlags.UpdateCurrent); Android.Gms.Common.Apis.IPendingResult iAddPendingResult = LocationServices.GeofencingApi.AddGeofences(ILocationServiceApi, geofenceRequest, pendingIntent); iAddPendingResult.SetResultCallback(this); }