GPS Intermediate Driver Constantly Return 0 0 LAT

2019-09-16 05:16发布

问题:

I am confused because I know my GPS Device State and Service State are both ON, yet Satellites in View, and Latitude/Longitude are both blank. I have configured my programs to use port GPD1, and my Hardware uses COM7. This seems to be the correct configuration. Why am I getting nothing returned?

回答1:

Latitude and Longitude are only filled if there is a Fix (a valid geo position):

            // call native method passing in our native buffer
            int result = GPSGetPosition(gpsHandle, ptr, 500000, 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;
                    }
                }
            }

For a Fix (a valid position) the GPS needs at least three valid satellites.

See my GPSsample I linked to your other question. It will show some more background information on what is going on with the GPS signals.

A tip: the time-to-first-fix (TTFF) may last up to 15-20 minutes with free view on the sky if there is no alternate EE data source and the GPS module is not moved to much. The EE data is built from the satellites broadcasts, the data rate is very low. The EE data can also be provided via a internet data connection, but the usage depends on the GPS module used. This EE data specifies the real position of all GPS satellites for two weeks. If a GPS receiver is switched off and moved ~200km, the location has to be calculated from base (may be another 15 minutes).

In reality, current GPS receivers provide alternate 'feeds' for EE data, for example GPSeXtra (internet data) or MS assisted GPS (cell phone tower ID and location).