public GeoCoordinate WhereShouldIBe(GeoCoordinate position) { //DateTime nowTime = new DateTime(2000, 1, 1, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); DateTime nowTime = new DateTime(2000, 1, 1, 14, 21, 0); DateTime EventStart = WayPoints.First().LegStartTime; DateTime EventEnd = WayPoints.Last().LegStartTime; if (DateTime.Compare(nowTime, EventStart) < 0) { StartWayPoint = WayPoints.First(); EndWayPoint = WayPoints.FirstOrDefault(w => w.Id == (StartWayPoint.Id + 1)); double xLat = StartWayPoint.Latitude; double xLong = StartWayPoint.Longitude; double timeToTurn = (StartWayPoint.LegStartTime - nowTime).TotalSeconds; double NextLeg = Trig.GetBearing(StartWayPoint.Latitude, StartWayPoint.Longitude, EndWayPoint.Latitude, EndWayPoint.Longitude, 11.0); return(new GeoCoordinate(xLat, xLong, timeToTurn, NextLeg, 0.0, 0.0, 0.0)); } else if (DateTime.Compare(nowTime, EventEnd) > 0) { return(null); } else { StartWayPoint = WayPoints.LastOrDefault(w => nowTime > w.LegStartTime); EndWayPoint = WayPoints.First(w => nowTime < w.LegStartTime); WayPoint NextWayPoint = WayPoints.FirstOrDefault(w => w.Id == (EndWayPoint.Id + 1)); double PercentDownLeg = ((nowTime - StartWayPoint.LegStartTime).TotalSeconds * 1000) / ((EndWayPoint.LegStartTime - StartWayPoint.LegStartTime).TotalSeconds) / 1000.0; double xLat = StartWayPoint.Latitude + (EndWayPoint.Latitude - StartWayPoint.Latitude) * PercentDownLeg; double xLong = StartWayPoint.Longitude + (EndWayPoint.Longitude - StartWayPoint.Longitude) * PercentDownLeg; double xTrack = Trig.CalcXTrack(position.Latitude, position.Longitude, StartWayPoint, EndWayPoint); double timeToTurn = Math.Round((EndWayPoint.LegStartTime - nowTime).TotalSeconds, 0); double NextLeg = Trig.GetBearing(EndWayPoint.Latitude, EndWayPoint.Longitude, NextWayPoint.Latitude, NextWayPoint.Longitude, 11.0); return(new GeoCoordinate(xLat, xLong, timeToTurn, NextLeg, 0.0, xTrack, 0.0)); } }