Bug in Sample Project - GPS Intermediate Driver WM5
I've detected a bug in class GPSPosition.cs in method
ParseDegreesMinutesSeconds, located in the Windows Mobile 5 SDK sample for
GPS Intermediate Driver.
Originally, this methos is like:
private DegreesMinutesSeconds ParseDegreesMinutesSeconds(double val)
{
double degrees = (val / 100.0);
double minutes = (Math.Abs(degrees) -
Math.Abs((double)(int)(degrees))) * 100;
double seconds = (Math.Abs(val) - Math.Abs((double)(int)val)) *
60.0;
return new DegreesMinutesSeconds((int)degrees, (int)minutes,
seconds);
}
Well, this implementation will cause a wrong translation of GPS coordinates
to Degrees-Minutes-Seconnds.
My fix is shown below:
private DegreesMinutesSeconds ParseDegreesMinutesSeconds(double val)
{
//double degrees = (val / 100.0);
//double minutes = (Math.Abs(degrees) -
Math.Abs((double)(int)(degrees))) * 100;
//double seconds = (Math.Abs(val) - Math.Abs((double)(int)val))
* 60.0;
/* MY FIX*/
// ->
double grados = Math.Round(val, 0);
double minutos = Math.Round((val - grados)*60, 0);
double segundos = Math.Round(((val - grados) * 60 - minutos) *
60, 0);
// <-
return new DegreesMinutesSeconds((int)grados, (int)minutos,
segundos);
}
I've only taken the int part of 'val' parameter and then calculated minutes
taking the decimal part, dividing it by 60. Simillary with seconds.
It's the right way cause i've compared my results with commercial software
one's.
I hope it to be useful.
date: Sat, 16 Feb 2008 17:50:01 -0800
author: el Púa el P?