Example #1
0
        public (double, double) ChangeCurrentLocation(Location location)
        {
            double elapsedTime = -1, distance = -1;

            if (MapsInitialized)
            {
                if (CurrentTrainingState != TrainingState.Started)
                {
                    CurrentLocation = location;
                    if (LastLocationAdded)
                    {
                        LastLocationAdded = false;
                        AllTrainingLocalizations.Add(CurrentTrainingLocalizations);
                        CurrentTrainingLocalizations = new List <Localization>();
                    }
                }
                else
                {
                    if (!LastLocationAdded)
                    {
                        AddLocationLineOnMap();
                        CurrentTrainingLocalizations.Add(new Localization
                        {
                            Date      = DateTime.Now,
                            Latitude  = CurrentLocation.Latitude,
                            Longitude = CurrentLocation.Longitude
                        });
                        LastLocationAdded = true;
                    }
                    else
                    {
                        distance    = MathHelper.HaversineDistance(location.Latitude, location.Longitude, CurrentLocation.Latitude, CurrentLocation.Longitude);
                        elapsedTime = (location.Time - CurrentLocation.Time);
                    }
                    CurrentLocation = location;
                    AddLocationLineOnMap();
                    CurrentTrainingLocalizations.Add(new Localization
                    {
                        Date      = DateTime.Now,
                        Latitude  = CurrentLocation.Latitude,
                        Longitude = CurrentLocation.Longitude
                    });
                    LastLocationAdded = true;
                }
                AnimateToCurrentLocation();
                SetCurrentLocationMarker();
            }
            else
            {
                AnimateToCurrentLocation();
                SetCurrentLocationMarker();
                CurrentLocation = location;
                MapsInitialized = true;
            }
            return(elapsedTime, distance);
        }
Example #2
0
        public void SaveTraining(TrainingType type, DateTime start, double distance, double time)
        {
            if (CurrentTrainingLocalizations.Count != 0)
            {
                AllTrainingLocalizations.Add(CurrentTrainingLocalizations);
            }
            Training training = new Training()
            {
                Distance  = distance,
                Time      = time,
                StartDate = start,
                EndDate   = DateTime.Now,
                Type      = type
            };

            logic.SaveTraining(training, AllTrainingLocalizations);
        }