NavigatorManaged.Navigator.LogLocation C# (CSharp) Method

LogLocation() public method

public LogLocation ( ) : Tuple
return Tuple
        public Tuple<string, string, string> LogLocation()
        {
            if (comPort.IsOpen())
            {
                Stopwatch s = new Stopwatch();
                s.Start();

                while (s.Elapsed < TimeSpan.FromSeconds(150))
                {
                    if (comPort.Latitude.ToString() != null || comPort.Longitude.ToString() != null || comPort.Speed.ToString() != null)
                    {
                        string latitudewithoffset;
                        string longitudewithoffset;
                        Routing.ApplyOffset(comPort.Latitude.ToString(), comPort.Longitude.ToString(), out latitudewithoffset, out longitudewithoffset);
                        return Tuple.Create(latitudewithoffset, longitudewithoffset, comPort.Speed.ToString());
                    }
                }

                return null;

            }
            else
            {
                return null;
                //throw new EntryPointNotFoundException(@"Com port is not opend");
            }
        }

Usage Example

Esempio n. 1
0
        private void OnTimedEvent(Navigator nav)
        {
            var result = nav.LogLocation();

            if (result != null)
            {
                var lat   = Math.Round(double.Parse(result.Item1), 4);
                var lon   = Math.Round(double.Parse(result.Item2), 4);
                var speed = Math.Round(double.Parse(result.Item3), 4);
                var data  = string.Format(@"Date:{0}, Time:{1}, Latitude:{2}, Longitude:{3}, CurrentSpeed:{4} km/h", DateTime.Now.Date, DateTime.Now.ToString("h:mm:ss tt"), lat, lon, speed);
                var data1 = string.Format(@"{0}, {1}, {2}, {3}, {4}", DateTime.Now.Date, DateTime.Now.ToString("h:mm:ss tt"), nav.getLatitude(), nav.getLongitude(), lat, lon, speed);
                Console.WriteLine(data);
                logger.Info(data1);
            }
        }