func TestToLatLonBadInput(t *testing.T) { for i, data := range badInputToLatLon { _, err := data.ToLatLon() if err == nil { t.Errorf("Expected error. badInputToLatLon TestToLatLonBadInput case %d", i) } } coordinate := UTM.Coordinate{ Easting: 377486, Northing: 6296562, ZoneNumber: 30, } _, err := coordinate.ToLatLon() if err == nil { t.Error("Expected error. too few arguments") } coordinate.ZoneLetter = "V" _, err = coordinate.ToLatLon(true) if err == nil { t.Error("Expected error. too many arguments") } letters := []string{ "X", "W", "V", "U", "T", "S", "R", "Q", "P", "N", "M", "L", "K", "J", "H", "G", "F", "E", "D", "C", "x", "w", "v", "u", "t", "s", "r", "q", "p", "n", "m", "l", "k", "j", "h", "g", "f", "e", "d", "c", } for _, letter := range letters { coordinate.ZoneLetter = letter _, err := coordinate.ToLatLon() if err != nil { t.Errorf("letter isn't covered. %s", letter) } } }
func TestToLatLonWithNorthern(t *testing.T) { for i, data := range knownValues { UTMwithNorthern := UTM.Coordinate{ Easting: data.UTM.Easting, Northing: data.UTM.Northing, ZoneNumber: data.UTM.ZoneNumber, } result, err := UTMwithNorthern.ToLatLon(data.northern) if err != nil { t.Fatal(err.Error()) } if round(data.LatLon.Latitude) != round(result.Latitude) { t.Errorf("Latitude TestToLatLonWithNorthern case %d", i) } if round(data.LatLon.Longitude) != round(result.Longitude) { t.Errorf("Longitude TestToLatLonWithNorthern case %d", i) } } }
func main() { latLon := UTM.LatLon{ Latitude: 40.71435, Longitude: -74.00597, } result, err := latLon.FromLatLon() if err != nil { panic(err.Error()) } fmt.Println( fmt.Sprintf( "Easting: %d; Northing: %d; ZoneNumber: %d; ZoneLetter: %s;", result.Easting, result.Northing, result.ZoneNumber, result.ZoneLetter, )) coordinateUTM := UTM.Coordinate{ Easting: 377486, Northing: 6296562, ZoneNumber: 30, } result1, err1 := coordinateUTM.ToLatLon(true) if err1 != nil { panic(err1.Error()) } fmt.Println(fmt.Sprintf("Latitude: %.5f; Longitude: %.5f;", result1.Latitude, result1.Longitude)) coordinateUTM.ZoneLetter = "V" result2, err2 := coordinateUTM.ToLatLon() if err2 != nil { panic(err2.Error()) } fmt.Println(fmt.Sprintf("Latitude: %.5f; Longitude: %.5f;", result2.Latitude, result2.Longitude)) }