public override void OnCreate()
        {
            mGeofenceList = new List <IGeofence>();
            Dictionary <string, double> nord = new Dictionary <string, double>()
            {
                { "lat", 39.716864 },
                { "lng", -104.955342 }
            };

            Dictionary <string, double> test = new Dictionary <string, double>()
            {
                { "lat", 39.716 },
                { "lng", -104.955 }
            };

            GeofencingClient geofencingClient = LocationServices.GetGeofencingClient(this);

            mGeofenceList.Add(new GeofenceBuilder()
                              .SetRequestId("nord")
                              .SetCircularRegion(nord["lat"], nord["lng"], 3f)
                              .SetExpirationDuration(Geofence.NeverExpire)
                              .SetTransitionTypes(Geofence.GeofenceTransitionEnter | Geofence.GeofenceTransitionExit)
                              .Build());

            geofencingClient.AddGeofences(GetGeofencingRequest(), GetGeofencePendingIntent());
            Console.WriteLine("WTF WTF WTF WTF");
            Log.Debug("THIS", "WTF Created!");
        }
Exemplo n.º 2
0
        private void AddGeofences()
        {
            if (!CheckPermissions())
            {
                ShowSnackbar(GetString(Resource.String.insufficient_permissions));
                return;
            }

            mGeofencingClient.AddGeofences(GetGeofencingRequest(), GetGeofencePendingIntent()).AddOnCompleteListener(this);
        }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
0
 /// <summary>
 /// ジオフェンスを追加します。
 /// </summary>
 public void AddGeofences()
 {
     _geofencingClient.AddGeofences(GetGeofencingRequest(), GetGeofencePendingIntent())
     .AddOnCompleteListener(this);
 }
        /// <summary>
        /// Adds geofences using Android's geofence client.
        /// </summary>
        public void AddGeofences()
        {
            try
            {
                // Operate on copy of regions to reduce scope of lock
                var regionsClone = new List <GeofenceCircularRegion>();

                lock (Lock)
                    foreach (var region in Regions.Values)
                    {
                        System.Diagnostics.Debug.WriteLine("Here is region " + region.Id);
                        regionsClone.Add(new GeofenceCircularRegion(region));
                        if (GeofenceStore.SharedInstance.Get(region.Id) == null)
                        {
                            GeofenceStore.SharedInstance.Save(region);
                        }
                    }

                mGeofenceList.Clear();
                foreach (GeofenceCircularRegion region in regionsClone)
                {
                    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)
                    {
                        mGeofenceList.Add(new Android.Gms.Location.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());
                        CrossGeofence.GeofenceListener.OnMonitoringStarted(region.Id);
                    }
                }

                System.Diagnostics.Debug.WriteLine("Add geofences");
                if (mGeofenceList.Count > 0)
                {
                    mGeofencingClient.AddGeofences(GetGeofencingRequest(mGeofenceList), GeofenceTransitionPendingIntent).AddOnCompleteListener(this);
                    CurrentRequestType = RequestType.Default;
                }
            }
            catch (Java.Lang.Exception ex1)
            {
                string message = string.Format("{0} - Error: {1}", CrossGeofence.Id, ex1.ToString());
                System.Diagnostics.Debug.WriteLine(message);
                CrossGeofence.GeofenceListener.OnError(message);
            }
            catch (System.Exception ex2)
            {
                string message = string.Format("{0} - Error: {1}", CrossGeofence.Id, ex2.ToString());
                System.Diagnostics.Debug.WriteLine(message);
                CrossGeofence.GeofenceListener.OnError(message);
            }
        }