Click to See Complete Forum and Search --> : [RESOLVED] Help with a function please?


trevorjdaniel
November 18th, 2009, 08:09 AM
Hi there,

Can anyone help me please?

I am developing a windows mobile application which talks to the GPS in the device to work out where some is.

The code is based on some MS source code which i found on the net.

But I have a problem with one of the functions. It seems to have a if statement which stops it working when the degrees is equal to zero, which it is in my part of the world. (UK)

I cannot seem to get my head around how to change the function to make it work even if the degrees is zero.

I have obviously tried taking out the "if" part but because the function includes dividing the result by the value of "degrees" it throws a divide by zero exception.

Here is the function:

/// <summary>
/// Converts the decimal, minutes, seconds coordinate to
/// decimal degrees
/// </summary>
/// <returns></returns>
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);
}

Can anyone help me please?

Many thanks in advance

Trev

trevorjdaniel
November 18th, 2009, 08:37 AM
Please ignore this message I have now found the answer...

http://social.msdn.microsoft.com/Forums/en-US/windowsmobiledev/thread/f0a362e8-d24c-4acf-802c-48a2ba36254c