Пример #1
0
        void gps_LocationChanged(object sender, GpsPosition position)
        {
            try
            {
                if (position != null)
                {
                    count++;

                    //Debug.WriteLine("LocationChanged: " + DateTime.Now.ToLongTimeString() + " -> " + count);

                    if (position.Time.HasValue && position.Latitude.HasValue && position.Longitude.HasValue)
                    {
                        //Debug.WriteLine("Location: " + position.Latitude.Value + "|" + position.Longitude.Value);

                        // first time
                        if (!TimeUTC.HasValue)
                        {
                            TimeUTC = position.Time;
                            Lat     = position.Latitude;
                            Lng     = position.Longitude;
                        }

                        if (TimeUTC.HasValue && position.Time - TimeUTC.Value >= delay)
                        {
                            Delta   = gps.GetDistance(position.Latitude.Value, position.Longitude.Value, Lat.Value, Lng.Value);
                            Total  += Delta;
                            Lat     = position.Latitude;
                            Lng     = position.Longitude;
                            TimeUTC = position.Time;

                            AddToLogCurrentInfo(position);
                        }
                    }
                    else
                    {
                        Lat     = position.Latitude;
                        Lng     = position.Longitude;
                        TimeUTC = position.Time;
                    }

                    // do not update if user is idling
                    if (IsVisible)
                    {
                        lock (Satellites)
                        {
                            Satellites.Clear();
                            Satellites.AddRange(position.GetSatellitesInView());
                            Satellites.TrimExcess();
                        }

                        Invoke(updateDataHandler, position);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("gps_LocationChanged: " + ex);
            }
        }