-
Notifications
You must be signed in to change notification settings - Fork 0
/
loctools.go
51 lines (40 loc) · 1.24 KB
/
loctools.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
package loctools
import (
"net/http"
gogeouri "git.jlel.se/jlelse/go-geouri"
)
type Location struct {
Latitude float64 `json:"latitude,omitempty" yaml:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty" yaml:"longitude,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Locality string `json:"locality,omitempty" yaml:"locality,omitempty"`
Region string `json:"region,omitempty" yaml:"region,omitempty"`
Country string `json:"country-name,omitempty" yaml:"country-name,omitempty"`
}
type LocTools struct {
httpClient *http.Client
}
func NewLocTools(client *http.Client) *LocTools {
if client == nil {
client = &http.Client{}
}
return &LocTools{
httpClient: client,
}
}
func (l *LocTools) Reverse(lang string, lon, lat float64) (*Location, error) {
return l.photonReverse(lang, lon, lat)
}
func (l *LocTools) FromGeoURI(lang, geouri string) (*Location, error) {
geo, err := gogeouri.Parse(geouri)
if err != nil {
return nil, err
}
return l.Reverse(lang, geo.Longitude, geo.Latitude)
}
func (l *LocTools) Search(lang, query string) (*Location, error) {
return l.photonSearch(lang, query)
}
func (l *LocTools) Airport(query string) (*Location, error) {
return l.aviowikiSearch(query)
}