2021-10-11 09:18:28 +01:00
package geocoding
import (
2021-11-01 11:00:21 +00:00
"go.m3o.com/client"
2021-10-11 09:18:28 +01:00
)
2021-12-30 08:44:34 +00:00
type Geocoding interface {
Lookup ( * LookupRequest ) ( * LookupResponse , error )
Reverse ( * ReverseRequest ) ( * ReverseResponse , error )
}
2021-10-11 09:18:28 +01:00
func NewGeocodingService ( token string ) * GeocodingService {
return & GeocodingService {
client : client . NewClient ( & client . Options {
Token : token ,
} ) ,
}
}
type GeocodingService struct {
client * client . Client
}
// Lookup returns a geocoded address including normalized address and gps coordinates. All fields are optional, provide more to get more accurate results
func ( t * GeocodingService ) Lookup ( request * LookupRequest ) ( * LookupResponse , error ) {
2021-12-21 13:18:29 +00:00
2021-10-11 09:18:28 +01:00
rsp := & LookupResponse { }
return rsp , t . client . Call ( "geocoding" , "Lookup" , request , rsp )
2021-12-21 13:18:29 +00:00
2021-10-11 09:18:28 +01:00
}
// Reverse lookup an address from gps coordinates
func ( t * GeocodingService ) Reverse ( request * ReverseRequest ) ( * ReverseResponse , error ) {
2021-12-21 13:18:29 +00:00
2021-10-11 09:18:28 +01:00
rsp := & ReverseResponse { }
return rsp , t . client . Call ( "geocoding" , "Reverse" , request , rsp )
2021-12-21 13:18:29 +00:00
2021-10-11 09:18:28 +01:00
}
type Address struct {
City string ` json:"city" `
Country string ` json:"country" `
2021-12-21 13:18:29 +00:00
LineOne string ` json:"line_one" `
LineTwo string ` json:"line_two" `
2021-10-11 09:18:28 +01:00
Postcode string ` json:"postcode" `
}
type Location struct {
Latitude float64 ` json:"latitude" `
Longitude float64 ` json:"longitude" `
}
type LookupRequest struct {
Address string ` json:"address" `
City string ` json:"city" `
Country string ` json:"country" `
Postcode string ` json:"postcode" `
}
type LookupResponse struct {
Address * Address ` json:"address" `
Location * Location ` json:"location" `
}
type ReverseRequest struct {
Latitude float64 ` json:"latitude" `
Longitude float64 ` json:"longitude" `
}
type ReverseResponse struct {
Address * Address ` json:"address" `
Location * Location ` json:"location" `
}