public Coordinates GetPosition(int maxAge)
        {
            Coordinates retCoords = new Coordinates();

            if (_gpsDeviceState != null &&
                _gpsDeviceState.DeviceState == GpsServiceState.On &&
                _gpsDeviceState.ServiceState == GpsServiceState.On)
            {
                //TimeSpan maxage = new TimeSpan(0, 0, 1);
                GpsPosition position = _gps.GetPosition(maxAge);
                if (position.LatitudeValid && position.LongitudeValid)
                {
                    retCoords.Latitude  = position.Latitude;
                    retCoords.Longitude = position.Longitude;
                }
            }

            return(retCoords);
        }
Beispiel #2
0
        /// <summary>
        /// Get the position reported by the GPS receiver that is no older than
        /// the maxAge passed in
        /// </summary>
        /// <param name="maxAge">Max age (int milisecs) of the gps position data that you want back.
        /// If there is no data within the required age, null is returned.
        /// <returns>GpsPosition class with all the position details</returns>
        public GpsPosition GetPosition(int maxAge)
        {
            GpsPosition gpsPosition = null;

            if (Opened)
            {
                // allocate the necessary memory on the native side.  We have a class (GpsPosition) that
                // has the same memory layout as its native counterpart
                IntPtr ptr = Utils.LocalAlloc(Marshal.SizeOf(typeof(GpsPosition)));

                // fill in the required fields
                gpsPosition           = new GpsPosition();
                gpsPosition.dwVersion = 1;
                gpsPosition.dwSize    = Marshal.SizeOf(typeof(GpsPosition));

                // Marshal our data to the native pointer we allocated.
                Marshal.StructureToPtr(gpsPosition, ptr, false);

                // call native method passing in our native buffer
                //int result = GPSGetPosition(gpsHandle, ptr, 500000, 0);
                int result = GPSGetPosition(gpsHandle, ptr, maxAge, 0);
                if (result == 0)
                {
                    // native call succeeded, marshal native data to our managed data
                    gpsPosition = (GpsPosition)Marshal.PtrToStructure(ptr, typeof(GpsPosition));

                    //if (maxAge != TimeSpan.Zero)
                    //{
                    //    // check to see if the data is recent enough.
                    //    if (!gpsPosition.TimeValid || DateTime.Now - maxAge > gpsPosition.Time)
                    //    {
                    //        gpsPosition = null;
                    //    }
                    //}
                }

                // free our native memory
                Utils.LocalFree(ptr);
            }

            return(gpsPosition);
        }
Beispiel #3
0
 public LocationChangedEventArgs(GpsPosition position)
 {
     this.position = position;
 }
 public LocationChangedEventArgs(GpsPosition position)
 {
     this.position = position;
 }
Beispiel #5
0
        /// <summary>
        /// Get the position reported by the GPS receiver that is no older than
        /// the maxAge passed in
        /// </summary>
        /// <param name="maxAge">Max age (int milisecs) of the gps position data that you want back. 
        /// If there is no data within the required age, null is returned.  
        /// <returns>GpsPosition class with all the position details</returns>
        public GpsPosition GetPosition(int maxAge)
        {
            GpsPosition gpsPosition = null;
            if (Opened)
            {
                // allocate the necessary memory on the native side.  We have a class (GpsPosition) that
                // has the same memory layout as its native counterpart
                IntPtr ptr = Utils.LocalAlloc(Marshal.SizeOf(typeof(GpsPosition)));

                // fill in the required fields
                gpsPosition = new GpsPosition();
                gpsPosition.dwVersion = 1;
                gpsPosition.dwSize = Marshal.SizeOf(typeof(GpsPosition));

                // Marshal our data to the native pointer we allocated.
                Marshal.StructureToPtr(gpsPosition, ptr, false);

                // call native method passing in our native buffer
                //int result = GPSGetPosition(gpsHandle, ptr, 500000, 0);
                int result = GPSGetPosition(gpsHandle, ptr, maxAge, 0);
                if (result == 0)
                {
                    // native call succeeded, marshal native data to our managed data
                    gpsPosition = (GpsPosition)Marshal.PtrToStructure(ptr, typeof(GpsPosition));

                    //if (maxAge != TimeSpan.Zero)
                    //{
                    //    // check to see if the data is recent enough.
                    //    if (!gpsPosition.TimeValid || DateTime.Now - maxAge > gpsPosition.Time)
                    //    {
                    //        gpsPosition = null;
                    //    }
                    //}
                }

                // free our native memory
                Utils.LocalFree(ptr);
            }

            return gpsPosition;
        }