-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFix.cs
50 lines (44 loc) · 1.66 KB
/
Fix.cs
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
using System;
using System.Globalization;
using System.Text;
namespace NATPlugin
{
public class Fix
{
public string Name { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
public Fix(string name, double lat = 0.0, double lon = 0.0)
{
this.Name = name;
this.Latitude = lat;
this.Longitude = lon;
}
public string Coordinate()
{
StringBuilder stringBuilder = new StringBuilder();
NumberFormatInfo invariantInfo = NumberFormatInfo.InvariantInfo;
GetDM(out var latDeg, out var latMin, out var north, out var lonDeg, out var lonMin, out var east);
stringBuilder.AppendFormat(invariantInfo, "{0:0#}{1:0#}{2}", latDeg, latMin, north ? "N" : "S");
stringBuilder.AppendFormat(invariantInfo, "{0:0##}{1:0#}{2}", lonDeg, lonMin, east ? "E" : "W");
return stringBuilder.ToString();
}
public void GetDM(out float latDeg, out float latMin, out bool north, out float lonDeg, out float lonMin, out bool east)
{
double latitude = Latitude;
north = latitude >= 0.0;
double num = Math.Abs(latitude);
latDeg = (float)Math.Truncate(num);
num -= (double)latDeg;
num *= 60.0;
latMin = (float)num;
double longitude = Longitude;
east = longitude >= 0.0;
double num2 = Math.Abs(longitude);
lonDeg = (float)Math.Truncate(num2);
num2 -= (double)lonDeg;
num2 *= 60.0;
lonMin = (float)num2;
}
}
}