/// <summary> /// Parses a Degrees, Minutes, Seconds coordinate to a string. /// </summary> /// <param name="coordinate">Coordinate</param> /// <param name="type">Coordinate Type</param> /// <returns>A string of Degrees, Minutes, Seconds</returns> private string ParseToDegreesMinutesSeconds(double coordinate, CoordinateReferenceType type) { char Direction; if (type == CoordinateReferenceType.Longitude) { Direction = (coordinate < 0) ? 'W' : 'E'; } else { Direction = (coordinate < 0) ? 'S' : 'N'; } coordinate = Math.Abs(coordinate); int Degrees = (int)(coordinate); int Minutes = (int)((coordinate - Degrees) * 60); double Seconds = ((coordinate - Degrees) * 60 - Minutes) * 60; // return Degrees.ToString("00" + ((type == CoordinateReferenceType.Longitude) ? "0" : "")) + "°" + Minutes.ToString("00") + "'" + Seconds.ToString("00.##") + "\"" + Direction; // Above make longitude degrees 3 places and latitude 2; do neither and // only show what is needed (match Google Maps output) return(Degrees.ToString() + "°" + Minutes.ToString("00") + "'" + DecimalFormat.Format(Seconds, 2) + "\"" + Direction); }
/// <summary> /// Parses a Degrees, Decimal Minutes coordinate to a string. /// </summary> /// <param name="coordinate">Coordinate</param> /// <param name="type">Coordinate Type</param> /// <returns>A string of Degrees, Decimal Minutes</returns> private string ParseToDegreesDecimalMinutes(double coordinate, CoordinateReferenceType type) { char Direction; if (type == CoordinateReferenceType.Longitude) { Direction = (coordinate < 0) ? 'W' : 'E'; } else { Direction = (coordinate < 0) ? 'S' : 'N'; } coordinate = Math.Abs(coordinate); int Degrees = (int)(coordinate); double Minutes = (coordinate - Degrees) * 60; return(Degrees.ToString("00" + ((type == CoordinateReferenceType.Longitude) ? "0" : "")) + "°" + DecimalFormat.Format(Minutes, 5) + "'" + Direction); }