public async void StartMonitoring(GeofenceRegion region) { var geofence = new GeofenceBuilder() .SetRequestId(region.Identifier) .SetExpirationDuration(Geofence.NeverExpire) .SetCircularRegion( region.Center.Latitude, region.Center.Longitude, Convert.ToSingle(region.Radius.TotalMeters) ) .SetTransitionTypes( Geofence.GeofenceTransitionEnter | Geofence.GeofenceTransitionExit ) .Build(); var request = new GeofencingRequest.Builder() .AddGeofence(geofence) .SetInitialTrigger(GeofencingRequest.InitialTriggerEnter | GeofencingRequest.InitialTriggerExit) .Build(); await client.AddGeofencesAsync(request, GetPendingIntent()); lock (syncLock) { regions.Add(region); MarcelloDatabase.Current.Save(region); //if (regions.Count == 1) // Application.Context.StartForegroundService(new Intent(Application.Context, typeof(GeofenceBroadcastReceiver))); } }
private GeofencingRequest GetGeofencingRequest() { GeofencingRequest.Builder builder = new GeofencingRequest.Builder(); builder.SetInitialTrigger(GeofencingRequest.InitialTriggerEnter); builder.AddGeofences(mGeofenceList); return(builder.Build()); }
protected virtual async Task Create(GeofenceRegion region) { var transitions = this.GetTransitions(region); var geofence = new GeofenceBuilder() .SetRequestId(region.Identifier) .SetExpirationDuration(Geofence.NeverExpire) .SetCircularRegion( region.Center.Latitude, region.Center.Longitude, Convert.ToSingle(region.Radius.TotalMeters) ) .SetTransitionTypes(transitions) .Build(); var request = new GeofencingRequest.Builder() .SetInitialTrigger(0) .AddGeofence(geofence) .Build(); await this.client .AddGeofencesAsync( request, this.GetPendingIntent() ) .ConfigureAwait(false); }
public override async Task StartMonitoring(GeofenceRegion region) { var transitions = this.GetTransitions(region); var geofence = new GeofenceBuilder() .SetRequestId(region.Identifier) .SetExpirationDuration(Geofence.NeverExpire) .SetCircularRegion( region.Center.Latitude, region.Center.Longitude, Convert.ToSingle(region.Radius.TotalMeters) ) .SetTransitionTypes(transitions) .Build(); var request = new GeofencingRequest.Builder() .AddGeofence(geofence) .SetInitialTrigger(transitions) .Build(); await this.client.AddGeofences( request, this.GetPendingIntent() ); await this.Repository.Set(region.Identifier, region); }
private async void SetGeofence() { var locationClient = LocationServices.GetFusedLocationProviderClient(this); var geofencingClient = LocationServices.GetGeofencingClient(this); var lastLocation = await locationClient.GetLastLocationAsync(); var geoFence = new GeofenceBuilder() .SetRequestId("fence") .SetCircularRegion(lastLocation.Latitude, lastLocation.Longitude, 100) .SetTransitionTypes(Geofence.GeofenceTransitionExit | Geofence.GeofenceTransitionEnter) .SetExpirationDuration(Geofence.NeverExpire) .Build(); var geofenceRequest = new GeofencingRequest.Builder() .AddGeofence(geoFence) .Build(); var geoIntent = new Intent(ApplicationContext, typeof(GeofenceTransitionsService)); var pendingGeoIntent = PendingIntent.GetService(this, 0, geoIntent, PendingIntentFlags.UpdateCurrent); geofencingClient.AddGeofences(geofenceRequest, pendingGeoIntent); }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); var locationClient = LocationServices.GetFusedLocationProviderClient(this); var geofencingClient = LocationServices.GetGeofencingClient(this); var lastLocation = await locationClient.GetLastLocationAsync(); var geoFence = new GeofenceBuilder() .SetRequestId("fence") .SetCircularRegion(lastLocation.Latitude, lastLocation.Longitude, 100) .SetTransitionTypes(Geofence.GeofenceTransitionExit | Geofence.GeofenceTransitionEnter) .SetExpirationDuration(Geofence.NeverExpire) .Build(); var geofenceRequest = new GeofencingRequest.Builder() .SetInitialTrigger(GeofencingRequest.InitialTriggerEnter) .AddGeofence(geoFence) .Build(); var geoIntent = new Intent(this, typeof(GeofenceTransitionsService)); var pendingGeoIntent = PendingIntent.GetService(this, 0, geoIntent, PendingIntentFlags.UpdateCurrent); geofencingClient.AddGeofences(geofenceRequest, pendingGeoIntent); }
/// <summary> /// GeofencingRequestを生成して返します。 /// </summary> /// <returns>The geofencing request.</returns> private GeofencingRequest GetGeofencingRequest() { GeofencingRequest.Builder builder = new GeofencingRequest.Builder(); //builder.SetInitialTrigger(NO_INITIAL_TRIGGER); builder.SetInitialTrigger(GeofencingRequest.InitialTriggerEnter); builder.AddGeofences(Geofences); return(builder.Build()); }
private GeofencingRequest CreateGeofencingRequest(IGeofence geofence) { var builder = new GeofencingRequest.Builder(); builder.SetInitialTrigger(GeofencingRequest.InitialTriggerEnter); builder.AddGeofence(geofence); return(builder.Build()); }
private GeofencingRequest GetGeofencingRequest(IList <Android.Gms.Location.IGeofence> geofenceList) { GeofencingRequest.Builder builder = new GeofencingRequest.Builder(); builder.SetInitialTrigger(GeofencingRequest.InitialTriggerEnter); builder.AddGeofences(geofenceList); System.Diagnostics.Debug.WriteLine("Request"); return(builder.Build()); }
GeofencingRequest GetGeofencingRequest() { var builder = new GeofencingRequest.Builder(); builder.SetInitialTrigger(GeofencingRequest.InitialTriggerEnter); builder.AddGeofences(_geoList); return(builder.Build()); }
public GeofencingRequest GetAddGeofencingRequest(IGeofence geofence) { List <IGeofence> geofencesToAdd = new List <IGeofence>(); geofencesToAdd.Add(geofence); GeofencingRequest.Builder builder = new GeofencingRequest.Builder(); builder.SetInitialTrigger(GeofencingRequest.InitialTriggerEnter); builder.AddGeofences(geofencesToAdd); return(builder.Build()); }
public void Monitor(Location location) { var geofence = new GeofenceBuilder() .SetRequestId(location.Id.ToString()) .SetCircularRegion(location.lat, location.lon, (float)location.Radius) .SetTransitionTypes(Geofence.GeofenceTransitionEnter) .SetExpirationDuration(Geofence.NeverExpire) .Build(); var request = new GeofencingRequest.Builder() .AddGeofence(geofence) .Build(); LocationServices.GeofencingApi.AddGeofences(client, request, PendingIntent.GetService(Application.Context, 0, new Intent(Application.Context, new GeofenceService().Class), PendingIntentFlags.UpdateCurrent)); }
private void AddProximityAlert(double latitude, double longitude, string poiName, Action <int> enterWork = null, Action <int> exitWork = null) { #region SETUP CODE FOR RECEIVER //NOTE: this hash region does not actually build the geofence it is just setup code. //register enter and exit actions //this is the method that talks to the GeofenceTriggerReceiver receiver.RegisterActions(requestCode, enterWork, exitWork); //creating the receiver Bundle extras = new Bundle(); extras.PutString("name", poiName); extras.PutInt("id", requestCode); Intent intent = new Intent(GeofenceTriggerReceiver.IntentName); intent.PutExtra(GeofenceTriggerReceiver.IntentName, extras); var pendingIntent = PendingIntent.GetBroadcast(this, requestCode, intent, PendingIntentFlags.CancelCurrent); #endregion #region building the geofence if (apiClient != null) { IGeofence geofence = new GeofenceBuilder() .SetTransitionTypes(Geofence.GeofenceTransitionEnter | Geofence.GeofenceTransitionExit) .SetCircularRegion(latitude, longitude, 50) .SetRequestId(requestCode.ToString()) .SetExpirationDuration(Geofence.NeverExpire) .Build(); GeofencingRequest request = new GeofencingRequest.Builder() .AddGeofence(geofence) .Build(); LocationServices.GeofencingApi.AddGeofences(apiClient, request, pendingIntent); } activeGeofences.Add(requestCode, pendingIntent); //requestcode increases as geofence locations increase requestCode++; #endregion }
public void OnConnected(Bundle connectionHint) { var geofence = new GeofenceBuilder () .SetCircularRegion (42.3633025622483, -71.0857580911102, 100) .SetExpirationDuration (Geofence.NeverExpire) .SetRequestId ("org.neteril.Cytotem") .SetTransitionTypes (Geofence.GeofenceTransitionEnter) .SetNotificationResponsiveness ((int)TimeSpan.FromMinutes (10).TotalMilliseconds) .Build (); var request = new GeofencingRequest.Builder () .AddGeofence (geofence) .SetInitialTrigger (GeofencingRequest.InitialTriggerEnter) .Build (); var intent = new Intent (this, typeof(GeofenceService)); var pendingIntent = PendingIntent.GetService (this, 0, intent, PendingIntentFlags.UpdateCurrent); LocationServices.GeofencingApi.AddGeofences (client, request, pendingIntent); Android.Util.Log.Info ("GeofenceApi", "Successfully added geofence"); }
public void SetGeofences(List <Position> targets, Position currentPosition) { List <Position> nearTargets = GetCloseTargets(targets, currentPosition); List <IGeofence> geofences = new List <IGeofence>(); foreach (Position item in nearTargets) { IGeofence geofence = new GeofenceBuilder() .SetRequestId($"{item.Latitude}_{item.Longitude}") .SetCircularRegion(item.Latitude, item.Longitude, 1000) .SetLoiteringDelay(60 * 1000) .SetTransitionTypes(Geofence.GeofenceTransitionEnter | Geofence.GeofenceTransitionExit | Geofence.GeofenceTransitionDwell) .SetExpirationDuration((long)365 * 24 * 60 * 60 * 1000) .Build(); geofences.Add(geofence); } GeofencingRequest geofencingRequest = new GeofencingRequest.Builder() .AddGeofences(geofences) .Build(); geofencingClient.AddGeofences(geofencingRequest, GetGeofencePendingIntent()); }
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); }
private void AddGeofences() { try { List<Android.Gms.Location.IGeofence> geofenceList = new List<Android.Gms.Location.IGeofence>(); var regions = Regions.Values; foreach (GeofenceCircularRegion region in regions) { int transitionTypes = 0; if(region.NotifyOnStay) { transitionTypes |= Android.Gms.Location.Geofence.GeofenceTransitionDwell; } if(region.NotifyOnEntry) { transitionTypes |= Android.Gms.Location.Geofence.GeofenceTransitionEnter; } if (region.NotifyOnExit) { transitionTypes |= Android.Gms.Location.Geofence.GeofenceTransitionExit; } if(transitionTypes != 0) { geofenceList.Add(new GeofenceBuilder() .SetRequestId(region.Id) .SetCircularRegion(region.Latitude, region.Longitude, (float)region.Radius) .SetLoiteringDelay((int)region.StayedInThresholdDuration.TotalMilliseconds) //.SetNotificationResponsiveness(mNotificationResponsivness) .SetExpirationDuration(Android.Gms.Location.Geofence.NeverExpire) .SetTransitionTypes(transitionTypes) .Build()); if (GeofenceStore.SharedInstance.Get(region.Id) == null) { GeofenceStore.SharedInstance.Save(region); } CrossGeofence.GeofenceListener.OnMonitoringStarted(region.Id); } } if(geofenceList.Count>0) { GeofencingRequest request = new GeofencingRequest.Builder().SetInitialTrigger(GeofencingRequest.InitialTriggerEnter).AddGeofences(geofenceList).Build(); LocationServices.GeofencingApi.AddGeofences(mGoogleApiClient, request, GeofenceTransitionPendingIntent).SetResultCallback(this); CurrentRequestType = RequestType.Default; } }catch(Exception ex1) { string message = string.Format("{0} - Error: {1}", CrossGeofence.Id, ex1); Debug.WriteLine(message); CrossGeofence.GeofenceListener.OnError(message); } catch (System.Exception ex2) { string message = string.Format("{0} - Error: {1}", CrossGeofence.Id, ex2.ToString()); Debug.WriteLine(message); CrossGeofence.GeofenceListener.OnError(message); } }
private void AddFences() { pendingIntent = CreatePendingIntent(); GeofencingRequest fenceReq = new GeofencingRequest.Builder().AddGeofences(fencesToAdd).Build(); currentStage = FencingStage.Adding; var result = LocationServices.GeofencingApi.AddGeofences(googleApiClient, fenceReq, pendingIntent); result.SetResultCallback(this); }
GeofencingRequest GetGeofencingRequest() { var builder = new GeofencingRequest.Builder(); builder.SetInitialTrigger(GeofencingRequest.InitialTriggerEnter); builder.AddGeofences(mGeofenceList); return builder.Build(); }
private GeofencingRequest getGeofencingRequest() { GeofencingRequest.Builder builder = new GeofencingRequest.Builder (); builder.SetInitialTrigger (GeofencingRequest.InitialTriggerEnter); builder.AddGeofences (geofenceList); return builder.Build (); }