Exemplo n.º 1
0
        public static Location GetLocation(FlightPlan flightPlan, DateTime dateTime)
        {
            long airtimeSeconds = DateUtil.CalcDiffInSec(dateTime,
                                                         flightPlan.Initial_Location.Date_Time);
            long    secInSegmentsSoFar = 0;
            Segment currentSeg = null, lastSeg = null;

            // Add all segment seconds so far
            foreach (Segment segment in flightPlan.Segments)
            {
                secInSegmentsSoFar += segment.Timespan_Seconds;
                if (secInSegmentsSoFar >= airtimeSeconds)
                {
                    currentSeg          = segment;
                    secInSegmentsSoFar -= segment.Timespan_Seconds;
                    break;
                }
                lastSeg = segment;
            }

            // Get the fraction of segment the plane is in
            float  secInCurrentSegment = Math.Abs(airtimeSeconds - secInSegmentsSoFar);
            double fraction            = secInCurrentSegment / currentSeg.Timespan_Seconds;

            Location fromLocation = flightPlan.Initial_Location;

            if (lastSeg != null)
            {
                fromLocation = new Location(lastSeg.Longitude, lastSeg.Latitude,
                                            DateTime.UtcNow);
            }

            Location toLocation = new Location(currentSeg.Longitude, currentSeg.Latitude,
                                               DateTime.UtcNow);

            return(GetIntermediateLocation(fromLocation, toLocation, fraction));
        }