Ich habe ein Motorola MC65-Gerät, das CE OS 5.2 ausgeführt wird. Ich bin dabei, eine gültige Zeit für das Gerät zu erhalten. Ich hatte den Eindruck, dass, da ich diese Daten von einem Satelliten empfange, würde es die richtige Zeit für den Standort wissen ...GPS gibt falschen Zeitstempel auf Windows Mobile CE 5.2 zurück
Ich erhalte das richtige Datum, aber die Zeit ist um 3 Stunden. Ich bin Eastern Zeitzone, das Gerät hat die richtige Zeitzone eingestellt und die Zeit auf dem Gerät ist jetzt 11:56 Uhr (Es ist off ich weiß), das GPS zurück 4:15 PM ...
Hier ist meine aktuelle Code, um die Zeit über GPS zu bekommen, ich Nutzung der GPS-Treiber von Microsoft machen (https://msdn.microsoft.com/en-us/library/bb202128.aspx):
public DateTime GetGPSTime()
{
Boolean satsInView = false;
Gps g = new Gps();
g.DeviceStateChanged += new DeviceStateChangedEventHandler(g_DeviceStateChanged);
g.Open();
Thread.Sleep(4000);
if (g.Opened)
{
if (deviceState.ServiceState == GpsServiceState.On)
{
GpsPosition pos = g.GetPosition(TimeSpan.Zero); //No Delay in time
if (pos != null)
{
//First check that we have sats visible for good GPS signal.
if (pos.SatellitesInViewCountValid)
{
if (pos.SatellitesInViewCount >= 1)
satsInView = true;
else
satsInView = false;
}
if (pos.TimeValid && satsInView)
{
g.Close();
g.DeviceStateChanged -= g_DeviceStateChanged;
return pos.Time; //Returned time obtained from GPS Obj
}
}
g.Close();
g.DeviceStateChanged -= g_DeviceStateChanged;
return Helper.GetSystemTimeToNow(); //If GPS obj is null, return current system time.
}
}
g.Close();
g.DeviceStateChanged -= g_DeviceStateChanged;
return Helper.GetSystemTimeToNow(); //If GPS obj is null, return current system time.
}
auch hier ist die Methode von der offiziell Microsoft Zwi Dient GPS-Code-Beispiele. Diese Methode wird von meinem Code oben genannt, GpsPosition pos = g.GetPosition(TimeSpan.Zero);
/// <summary>
/// Get the position reported by the GPS receiver that is no older than
/// the maxAge passed in
/// </summary>
/// <param name="maxAge">Max age of the gps position data that you want back.
/// If there is no data within the required age, null is returned.
/// if maxAge == TimeSpan.Zero, then the age of the data is ignored</param>
/// <returns>GpsPosition class with all the position details</returns>
public GpsPosition GetPosition(TimeSpan 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);
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;
}
}
}
else if (result == 87) // ERROR_INVALID_PARAMETER)
{
//
// TEMPORARY HACK
//
// http://blogs.msdn.com/cenet/archive/2007/12/06/gpsid-problem-workaround-on-recent-wm6-release.aspx
//
Utils.LocalFree(ptr);
// allocate the necessary memory on the native side. We have a class (GpsPosition) that
// has the same memory layout as its native counterpart
ptr = Utils.LocalAlloc(376);
// fill in the required fields
gpsPosition = new GpsPosition();
gpsPosition.dwVersion = 1;
gpsPosition.dwSize = 376;
// Marshal our data to the native pointer we allocated.
Marshal.StructureToPtr(gpsPosition, ptr, false);
// call native method passing in our native buffer
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;
}
}
}
}
// free our native memory
Utils.LocalFree(ptr);
}
return gpsPosition;
}
Vielen Dank für diese Antwort! – Dayan