www.pudn.com > GPSTest.rar > DegreesMinutesSeconds.cs
#region Using directives
using System;
#endregion
namespace Microsoft.WindowsMobile.Samples.Location
{
///
/// class that represents a gps coordinate in degrees, minutes, and seconds.
///
public class DegreesMinutesSeconds
{
int degrees;
///
/// The degrees unit of the coordinate
///
public int Degrees
{
get { return degrees; }
}
int minutes;
///
/// The minutes unit of the coordinate
///
public int Minutes
{
get { return minutes; }
}
double seconds;
///
/// The seconds unit of the coordinate
///
public double Seconds
{
get { return seconds; }
}
///
/// Constructs a new instance of DegreesMinutesSeconds converting
/// from decimal degrees
///
/// Initial value as decimal degrees
public DegreesMinutesSeconds(double decimalDegrees)
{
degrees = (int)decimalDegrees;
double doubleMinutes = (Math.Abs(decimalDegrees) - Math.Abs((double)degrees)) * 60.0;
minutes = (int)doubleMinutes;
seconds = (doubleMinutes - (double)minutes) * 60.0;
}
///
/// Constructs a new instance of DegreesMinutesSeconds
///
/// Degrees unit of the coordinate
/// Minutes unit of the coordinate
/// Seconds unit of the coordinate
public DegreesMinutesSeconds(int degrees, int minutes, double seconds)
{
this.degrees = degrees;
this.minutes = minutes;
this.seconds = seconds;
}
///
/// Converts the decimal, minutes, seconds coordinate to
/// decimal degrees
///
///
public double ToDecimalDegrees()
{
int absDegrees = Math.Abs(degrees);
double val = (double)absDegrees + ((double)minutes / 60.0) + ((double)seconds / 3600.0);
return val * (absDegrees / degrees);
}
///
/// Converts the instance to a string in format: D M' S"
///
/// string representation of degrees, minutes, seconds
public override string ToString()
{
return degrees + "d " + minutes + "' " + seconds + "\"";
}
}
}