-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgeocode.go
34 lines (31 loc) · 907 Bytes
/
geocode.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
package applemaps
import (
"context"
"net/url"
)
// Geocode returns the latitude and longitude of the specified address.
func (c *client) Geocode(ctx context.Context, query string, opts ...RequestOption) ([]Place, error) {
values := url.Values{}
values.Add("q", query)
for _, opt := range opts {
opt(values)
}
res, err := exec[SearchResponse](ctx, c, geocodeEndpoint, values)
if err != nil {
return nil, err
}
return res.Results, nil
}
// ReverseGeocode returns a slice of addresses present at the specified location coordinates.
func (c *client) ReverseGeocode(ctx context.Context, location Location, opts ...RequestOption) ([]Place, error) {
values := url.Values{}
values.Add("loc", location.String())
for _, opt := range opts {
opt(values)
}
res, err := exec[SearchResponse](ctx, c, reverseGeocodeEndpoint, values)
if err != nil {
return nil, err
}
return res.Results, nil
}