public string ToString(GpsPointFormatString format, GpsPointComponent gpsPointComponent) { double component; double componentCh; double degrees; double minutes; double seconds; string sign = string.Empty; switch (gpsPointComponent) { case GpsPointComponent.Latitude: component = Latitude; componentCh = LatitudeCh; break; default: component = Longitude; componentCh = LongitudeCh; break; } if (component < 0) { component *= (-1); sign = "-"; } switch (format) { case GpsPointFormatString.Degrees: degrees = component/3600; minutes = (degrees - Math.Floor(degrees)) * 60; seconds = (minutes - Math.Floor(minutes)) * 60; return sign + Math.Floor(degrees).ToString() + "°" + Math.Floor(minutes).ToString() + "'" + Math.Round(seconds, 2).ToString() + "\""; case GpsPointFormatString.DegreesAndMinutes: degrees = component / 3600; minutes = (degrees - Math.Floor(degrees)) * 60; return sign + Math.Floor(degrees).ToString() + "°" + Math.Round(minutes, 2).ToString() + "\""; case GpsPointFormatString.DegreesDecimal: return sign + (component / 3600).ToString(); case GpsPointFormatString.DegreesOnly: degrees = component / 3600; return sign + Math.Floor(degrees).ToString(); case GpsPointFormatString.MinutesOnly: degrees = component / 3600; minutes = Math.Round((degrees - Math.Floor(degrees)) * 60, 4); return sign + minutes.ToString(); case GpsPointFormatString.Swiss: return sign + componentCh.ToString(); default: return sign + component.ToString(); } }
public string ToString(GpsPointFormatString format, GpsPointComponent gpsPointComponent) { double component; double componentCh; double degrees; double minutes; double seconds; string sign = string.Empty; switch (gpsPointComponent) { case GpsPointComponent.Latitude: component = Latitude; componentCh = LatitudeCh; break; default: component = Longitude; componentCh = LongitudeCh; break; } if (component < 0) { component *= (-1); sign = "-"; } degrees = Math.Floor(component / 3600); minutes = Math.Floor((component - degrees * 3600) / 60); seconds = Math.Floor((component - degrees * 3600 - minutes * 60)); switch (format) { case GpsPointFormatString.CleanWGS84String: return sign + degrees.ToString() + "°" + minutes.ToString() + "'" + seconds.ToString() + "\""; case GpsPointFormatString.DegreesOnly: return sign + degrees.ToString(); case GpsPointFormatString.MinutesOnly: return sign + minutes.ToString(); case GpsPointFormatString.SecondsOnly: return sign + seconds.ToString(); case GpsPointFormatString.Swiss: return sign + componentCh.ToString(); default: return sign + component.ToString(); } }