private double CalculateWithHaversine(Position position, AlarmLocation alarmLocation)
        {
            var R = 6371d;
            var currentLatitude  = position.Latitude;
            var currentLongitude = position.Longitude;

            var alarmLatitude  = alarmLocation.Latitude;
            var alarmLongitude = alarmLocation.Longitude;

            var differenceLatitudes  = ToRadius(alarmLatitude - currentLatitude);
            var differenceLongitudes = ToRadius(alarmLongitude - currentLongitude);

            var a = Math.Sin(differenceLatitudes / 2d) * Math.Sin(differenceLatitudes / 2d) +
                    Math.Cos(ToRadius(currentLatitude)) * Math.Cos(ToRadius(alarmLatitude)) *
                    Math.Sin(differenceLongitudes / 2d) * Math.Sin(differenceLongitudes / 2d);

            var c = 2d * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1d - a));

            return(R * c);
        }
        private async void SaveAlarmAsync()
        {
            if (!string.IsNullOrEmpty(Name) && Distance > 0)
            {
                try
                {
                    var location = (await Geocoding.GetLocationsAsync(Name)).FirstOrDefault();

                    if (location != null)
                    {
                        var newLocationAlarm = new AlarmLocation(Name, Distance,
                                                                 location.Latitude, location.Longitude, true);

                        await mainPageFeatures.AddAlarmAsync(newLocationAlarm);

                        UserDialogs.Instance.Toast("Zapisano alarm.", TimeSpan.FromSeconds(3.0));
                        Debug.WriteLine(newLocationAlarm.ToString());
                    }

                    else
                    {
                        UserDialogs.Instance.Toast("Nie można zapisać alarmu. Sprawdź miejsce docelowe.", TimeSpan.FromSeconds(3.0));
                    }
                }
                catch (FeatureNotSupportedException fnsEx)
                {
                    Debug.WriteLine(fnsEx.Message);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }

            else
            {
                UserDialogs.Instance.Toast("Nie można zapisać alarmu.", TimeSpan.FromSeconds(3.0));
            }
        }
Beispiel #3
0
        public async Task RemoveAlarmAsync(AlarmLocation alarmlocation)
        {
            await DbConnection.CreateTableAsync <AlarmLocation>();

            await DbConnection.DeleteAsync(alarmlocation);
        }
Beispiel #4
0
        public async Task UpdateAlarmAsync(AlarmLocation alarmLocation)
        {
            await DbConnection.CreateTableAsync <AlarmLocation>();

            await DbConnection.UpdateAsync(alarmLocation);
        }
Beispiel #5
0
        public async Task AddAlarmAsync(AlarmLocation alarmLocation)
        {
            await DbConnection.CreateTableAsync <AlarmLocation>();

            await DbConnection.InsertAsync(alarmLocation);
        }
Beispiel #6
0
 public async Task AddAlarmAsync(AlarmLocation alarmLocation)
 {
     gpsListener.AddObserver(alarmLocation.Id);
     await alarmDatabase.AddAlarmAsync(alarmLocation);
 }
 private double CalculateDistance(Position position, AlarmLocation alarmLocation)
 {
     return(CalculateWithHaversine(position, alarmLocation));
 }