Example #1
0
        public void Update(BusCoordinates coords)
        {
            if (coords != null && !coords.Equals(Position))
            {
                Counter = Counter / 4;

                Position = coords;
                if (_geoFence.IsAtWeba(coords.Latitude, coords.Longitude))
                {
                    Console.WriteLine($"{Id} is at Weba");
                    IsAtStop        = true;
                    LastStopVisited = BusStop.Weba;
                }
                else if (_geoFence.IsAtJacobs(coords.Latitude, coords.Longitude))
                {
                    Console.WriteLine($"{Id} is at Jacob");
                    IsAtStop        = true;
                    LastStopVisited = BusStop.Jacob;
                }
                else
                {
                    IsAtStop = false;
                }
            }
            else
            {
                Position = coords;
                Counter  = Counter < 30 ? Counter + 1 : Counter;
            }
        }
        public PredictionMatch GetTimeTillArrival(BusCoordinates currentBusCoordinates, BusStop LastStop)
        {
            List <PredictionMatch> toEvaluate = LastStop == BusStop.Jacob ? _jacobToWeba : _webaToJacob;
            double          min      = GetDistance(currentBusCoordinates, toEvaluate[0].Latitude, toEvaluate[0].Longitude);
            PredictionMatch closests = toEvaluate[0];

            for (int i = 1; i < toEvaluate.Count; i++)
            {
                double currentDistance = GetDistance(currentBusCoordinates, toEvaluate[i].Latitude, toEvaluate[i].Longitude);
                if (currentDistance < min)
                {
                    min      = currentDistance;
                    closests = toEvaluate[i];
                }
            }
            return(closests);
        }
 private double GetDistance(BusCoordinates from, double latTo, double longTo)
 {
     return(Math.Sqrt((from.Latitude - latTo) * (from.Latitude - latTo) +
                      (from.Longitude - longTo) * (from.Longitude - longTo)));
 }