-
Notifications
You must be signed in to change notification settings - Fork 0
/
geo_coordinates.go
53 lines (39 loc) · 1.27 KB
/
geo_coordinates.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
53
package geo_coordinates
import (
"fmt"
)
const (
geoCoordinatesEndpoint = "/region/byGeoCoordinates"
)
type GeoCoordinates struct {
// The geographical ID of the city
CityGeoId int `json:"cityGeoId"`
// The geographical ID of the state
StateGeoId int `json:"stateGeoId"`
// The latitude coordinate of the city
Latitude float64 `json:"latitude"`
// The longitude coordinate of the city
Longitude float64 `json:"longitude"`
// The name of the city
CityName string `json:"cityName"`
// The name of the state, province, or territory of a country
StateName string `json:"stateName"`
// The name of the country
CountryName string `json:"countryName"`
// The ISO standard two-letter country code
CountryCode string `json:"countryCode"`
// The postal code
PostalCode string `json:"postalCode"`
// The ISO standard two-letter continent code
ContinentCode string `json:"continentCode"`
}
func (service *Service) GetByGeoCoordinates(latitude, longitude float64) (*GeoCoordinates, error) {
var region GeoCoordinates
queryParams := fmt.Sprintf("latitude=%f&longitude=%f", latitude, longitude)
fullEndpoint := fmt.Sprintf("%s?%s", geoCoordinatesEndpoint, queryParams)
err := service.Client.Read(fullEndpoint, ®ion)
if err != nil {
return nil, err
}
return ®ion, nil
}