-
Notifications
You must be signed in to change notification settings - Fork 39
/
geo.go
52 lines (42 loc) · 861 Bytes
/
geo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package ics
import (
"strconv"
)
// Geo has latitude and longitude from the the GEO property of an event
type Geo struct {
latStr string
lat *float64
longStr string
long *float64
}
// NewGeo creates a new Geo object
func NewGeo(lat string, long string) *Geo {
return &Geo{
latStr: lat,
longStr: long,
}
}
// Latitude returns the latitude value from Geo
func (g *Geo) Latitude() (float64, error) {
if g.lat != nil {
return *g.lat, nil
}
latVal, err := strconv.ParseFloat(g.latStr, 64)
if err != nil {
return 0, err
}
g.lat = &latVal
return latVal, nil
}
// Longitude returns the longitude value from Geo
func (g *Geo) Longitude() (float64, error) {
if g.long != nil {
return *g.long, nil
}
longVal, err := strconv.ParseFloat(g.longStr, 64)
if err != nil {
return 0, err
}
g.long = &longVal
return longVal, nil
}