示例#1
0
文件: Database.cs 项目: JonaLaw/Digyl
        public async Task <CoordinateItem> QueryCoordinatesAsync(Location at)
        {
            // this is not optimal, it should be replaced by a custom sqlite function
            List <CoordinateItem> coordinateItems = await _database.Table <CoordinateItem>().Where(c => c.IsOn).ToListAsync();

            foreach (CoordinateItem item in coordinateItems)
            {
                if (LocationDetails.IsInLocation(at, item))
                {
                    return(item);
                }
            }

            return(null);
            //return await _database.Table<CoordinateItem>().Where(c => c.IsOn &&
            //(Location.CalculateDistance(at, c.Latitude, c.Longitude, DistanceUnits.Kilometers) <= c.Radius)).FirstOrDefaultAsync();
        }
示例#2
0
        /*public async void StartLocationHandler()
         * {
         *
         * }*/

        public async Task UpdateLocation(double latitude, double longitude)
        {
            Location newLocation = new Location(latitude, longitude);

            Debug.WriteLine($"Updated location: ({latitude}, {longitude})");

            if (App.Settings.CoordinateTrackingEnabled)
            {
                if (trackedCoordinateItem != null)
                {
                    if (!LocationDetails.IsInLocation(newLocation, trackedCoordinateItem))
                    {
                        if (trackedCoordinateItem.OnExit)
                        {
                            _ = TriggerAlert(trackedCoordinateItem, false);
                        }
                        trackedCoordinateItem = null;
                    }
                    return;
                }

                CoordinateItem foundCoordinateItem = await App.Database.QueryCoordinatesAsync(newLocation);

                if (foundCoordinateItem != null)
                {
                    trackedCoordinateItem = foundCoordinateItem;
                    if (trackedCoordinateItem.OnEnter)
                    {
                        _ = TriggerAlert(trackedCoordinateItem, true);
                    }
                    return;
                }
            }

            /*else
             * {
             *  trackedCoordinateItem = null;
             * }*/

            if (App.Settings.PlaceTrackingEnabled)
            {
                if (trackedPlaceTypeItem != null)
                {
                    if (!LocationDetails.IsInLocation(newLocation, startLocation, App.Settings.PlaceTypeLeaveRadius))
                    {
                        List <string> foundPlaceTypes = await LocationDetails.GetNearbyPlaceTypes(newLocation);

                        if (foundPlaceTypes.Exists(x => x.Equals(trackedPlaceTypeItem.Name)))
                        {
                            startLocation = newLocation;
                        }
                        else
                        {
                            if (trackedPlaceTypeItem.OnExit)
                            {
                                _ = TriggerAlert(trackedPlaceTypeItem, false);
                            }
                            trackedPlaceTypeItem = null;
                        }
                    }
                    return;
                }
                else
                {
                    List <string> foundPlaceTypes = await LocationDetails.GetNearbyPlaceTypes(newLocation);

                    if (foundPlaceTypes.Any())
                    {
                        PlaceTypeItem foundPlaceTypeItem = await App.Database.QueryPlaceTypes(foundPlaceTypes);

                        if (foundPlaceTypeItem != null)
                        {
                            trackedPlaceTypeItem = foundPlaceTypeItem;
                            if (trackedPlaceTypeItem.OnEnter)
                            {
                                _ = TriggerAlert(trackedPlaceTypeItem, true);
                            }
                            startLocation = newLocation;
                            return;
                        }
                    }
                }
            }

            /*else
             * {
             *  trackedPlaceTypeItem = null;
             * }*/
        }