Categories
Windows Mobile

Fixing the Windows Mobile 5.0 GPS Sample Code

The Windows Mobile 5.0 Pocket PC SDK includes a C# sample application to P/Invoke into the new GPS API in Windows Mobile 5.0. However there are a couple of bugs in the code which make it awkward to work with. One is a simple divide-by-zero which is easily fixed, the other relates to the fact that there was a bug in the RTM build in the way the latitude and longitude were formatted in the RTM release of the platform. Luckily it was patched before any shipping device was released but it affects the original emulators shipped with the SDK. The documentation states that the latitude/longitude are in decimal degrees, but in the RTM release it actually contained the raw NMEA format. The following are the code replacements you should make to get the GPS sample working on your device.


DegreesMinutesSeconds.cs


public double ToDecimalDegrees()
{
  if (degrees == 0)
  {
    return 0.0;
  }

  int absDegrees = Math.Abs(degrees);

  double val = (double)absDegrees + ((double)minutes / 60.0) + ((double)seconds / 3600.0);

  return val * (absDegrees / degrees);
}


GpsPosition.cs


public double Latitude
{
    get { return dblLatitude; }
}


public double Longitude
{
    get { return dblLongitude; }
}


 


Full details on configuring your device to use GPS are here in Jason’s blog post.

By Peter Foot

Microsoft Windows Development MVP

2 replies on “Fixing the Windows Mobile 5.0 GPS Sample Code”

Hello,
i found a other Mistake in GpsPosition.cs
private DegreesMinutesSeconds ParseDegreesMinutesSeconds(double val)
{
double degrees = (val / 1.0);
double minutes = (Math.Abs(val) – Math.Abs((double)(int)val)) * 60.0;
double seconds = (Math.Abs(minutes) – Math.Abs((double)(int)minutes)) * 60.0;
return new DegreesMinutesSeconds((int)degrees, (int)minutes, seconds);
}

Comments are closed.