Add geo pkg
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user