public static CoordinateSet GridSquareToLatLon(string locator) { var coordinates = new CoordinateSet(); locator = locator.ToUpper(); if (locator.Length == 4) { locator += "IL"; //somewhere near the center of the grid } if (!Regex.IsMatch(locator, "^[A-R]{2}[0-9]{2}[A-X]{2}$")) { return(null); } coordinates.Longitude.Value = (locator[0] - 'A') * 20 + (locator[2] - '0') * 2 + (locator[4] - 'A' + 0.5) / 12 - 180; coordinates.Latitude.Value = (locator[1] - 'A') * 10 + (locator[3] - '0') + (locator[5] - 'A' + 0.5) / 24 - 90; return(coordinates); }
public static string LatLonToGridSquare(CoordinateSet coordinateSet) { return(LatLonToGridSquare(coordinateSet.Latitude.Value, coordinateSet.Longitude.Value)); }