Add geo pkg

This commit is contained in:
dwrz
2026-10-23 14:10:22 +00:00
parent 68623bb4e6
commit 936e7d38cb
2 changed files with 217 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
package geo
import (
"fmt"
"strconv"
"strings"
)
type Coordinates struct {
Latitude float64
Longitude float64
}
func ParseCoordinates(s string) (*Coordinates, error) {
parts := strings.Split(s, ",")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid string: %s", s)
}
var (
c = &Coordinates{}
err error
)
c.Latitude, err = strconv.ParseFloat(parts[0], 64)
if err != nil {
return nil, fmt.Errorf("failed to parse latitude: %v", err)
}
c.Longitude, err = strconv.ParseFloat(parts[1], 64)
if err != nil {
return nil, fmt.Errorf("failed to parse longitude: %v", err)
}
return c, nil
}