position.go 664 B

12345678910111213141516171819202122232425262728
  1. // SPDX-FileCopyrightText: Adam Evyčędo
  2. //
  3. // SPDX-License-Identifier: AGPL-3.0-or-later
  4. package traffic
  5. import (
  6. "fmt"
  7. "strconv"
  8. "strings"
  9. )
  10. func ParsePosition(location string) (Position, error) {
  11. locationString := strings.Split(location, ",")
  12. if len(locationString) != 2 {
  13. return Position{}, fmt.Errorf("location is not two numbers")
  14. }
  15. lat, err := strconv.ParseFloat(locationString[0], 64)
  16. if err != nil {
  17. return Position{}, fmt.Errorf("latitude is not a float")
  18. }
  19. lon, err := strconv.ParseFloat(locationString[1], 64)
  20. if err != nil {
  21. return Position{}, fmt.Errorf("longitude is not a float")
  22. }
  23. return Position{Lat: lat, Lon: lon}, nil
  24. }