Files
@ 65c134a3d619
Branch filter:
Location: seniordesign-ui/GMap.NET.WindowsMobile/GMap.NET.GPS/DegreesMinutesSeconds.cs
65c134a3d619
3.9 KiB
text/x-csharp
Initial import of mapping source (huge commit)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | //
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
#region Using directives
using System;
#endregion
namespace GMap.NET.GPS
{
/// <summary>
/// class that represents a gps coordinate in degrees, minutes, and seconds.
/// </summary>
public class DegreesMinutesSeconds
{
bool isPositive;
/// <summary>
/// Returns true if the degrees, minutes and seconds refer to a positive value,
/// false otherwise.
/// </summary>
public bool IsPositive
{
get
{
return isPositive;
}
}
uint degrees;
/// <summary>
/// The degrees unit of the coordinate
/// </summary>
public uint Degrees
{
get
{
return degrees;
}
}
uint minutes;
/// <summary>
/// The minutes unit of the coordinate
/// </summary>
public uint Minutes
{
get
{
return minutes;
}
}
double seconds;
/// <summary>
/// The seconds unit of the coordinate
/// </summary>
public double Seconds
{
get
{
return seconds;
}
}
/// <summary>
/// Constructs a new instance of DegreesMinutesSeconds converting
/// from decimal degrees
/// </summary>
/// <param name="decimalDegrees">Initial value as decimal degrees</param>
public DegreesMinutesSeconds(double decimalDegrees)
{
isPositive = (decimalDegrees > 0);
degrees = (uint) Math.Abs(decimalDegrees);
double doubleMinutes = (Math.Abs(decimalDegrees) - Math.Abs((double) degrees)) * 60.0;
minutes = (uint) doubleMinutes;
seconds = (doubleMinutes - (double) minutes) * 60.0;
}
/// <summary>
/// Constructs a new instance of DegreesMinutesSeconds
/// </summary>
/// <param name="isPositive">True if the coordinates are positive coordinate, false if they
/// are negative coordinates.</param>
/// <param name="degrees">Degrees unit of the coordinate</param>
/// <param name="minutes">Minutes unit of the coordinate</param>
/// <param name="seconds">Seconds unit of the coordinate. This should be a positive value.</param>
public DegreesMinutesSeconds(bool isPositive, uint degrees, uint minutes, double seconds)
{
this.isPositive = isPositive;
this.degrees = degrees;
this.minutes = minutes;
this.seconds = seconds;
}
/// <summary>
/// Converts the decimal, minutes, seconds coordinate to
/// decimal degrees
/// </summary>
/// <returns></returns>
public double ToDecimalDegrees()
{
double val = (double) degrees + ((double) minutes / 60.0) + ((double) seconds / 3600.0);
val = isPositive ? val : val * -1;
return val;
}
/// <summary>
/// Converts the instance to a string in format: D M' S"
/// </summary>
/// <returns>string representation of degrees, minutes, seconds</returns>
public override string ToString()
{
return degrees + "d " + minutes + "' " + seconds + "\"";
}
}
}
|