Make lead creation and invalidation for public reports work
The only thing wrong at this point that I can tell is that address aren't being correctly populated when I reverse geocode.
This commit is contained in:
parent
3e1b56a266
commit
e2af49a323
27 changed files with 821 additions and 365 deletions
69
stadia/geocode_raw.go
Normal file
69
stadia/geocode_raw.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
package stadia
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
)
|
||||
|
||||
type RequestGeocodeRaw struct {
|
||||
Text string `url:"text" json:"text"`
|
||||
|
||||
// Boundary circle parameters
|
||||
BoundaryCircleLat *float64 `url:"boundary.circle.lat,omitempty"`
|
||||
BoundaryCircleLon *float64 `url:"boundary.circle.lon,omitempty"`
|
||||
BoundaryCircleRadius *float64 `url:"boundary.circle.radius,omitempty"`
|
||||
|
||||
// Boundary parameters
|
||||
BoundaryRectMaxLat *float64 `url:"boundary.rect.max_lat,omitempty"`
|
||||
BoundaryRectMinLat *float64 `url:"boundary.rect.min_lat,omitempty"`
|
||||
BoundaryRectMaxLon *float64 `url:"boundary.rect.max_lon,omitempty"`
|
||||
BoundaryRectMinLon *float64 `url:"boundary.rect.min_lon,omitempty"`
|
||||
|
||||
// Focus point
|
||||
FocusPointLat *float64 `url:"focus.point.lat,omitempty" json:",omitempty"`
|
||||
FocusPointLng *float64 `url:"focus.point.lon,omitempty" json:",omitempty"`
|
||||
|
||||
// Other parameters
|
||||
Lang *string `url:"lang,omitempty" json:"lang,omitempty"`
|
||||
Layers []string `url:"layers,omitempty,comma" json:"layers,omitempty"`
|
||||
Sources []string `url:"sources,omitempty,comma" json:"sources,omitempty"`
|
||||
Size *int `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (r *RequestGeocodeRaw) SetBoundaryRect(xmin, ymin, xmax, ymax float64) {
|
||||
r.BoundaryRectMaxLat = &ymax
|
||||
r.BoundaryRectMinLat = &ymin
|
||||
r.BoundaryRectMaxLon = &xmax
|
||||
r.BoundaryRectMinLon = &xmin
|
||||
}
|
||||
func (r *RequestGeocodeRaw) SetFocusPoint(x, y float64) {
|
||||
r.FocusPointLat = &y
|
||||
r.FocusPointLng = &x
|
||||
}
|
||||
func (s *StadiaMaps) GeocodeRaw(ctx context.Context, req RequestGeocodeRaw) (*GeocodeResponse, error) {
|
||||
// https://docs.stadiamaps.com/geocoding-search-autocomplete/search/
|
||||
var result GeocodeResponse
|
||||
|
||||
query, err := query.Values(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("structured geocode query: %w", err)
|
||||
}
|
||||
//var api_error Error
|
||||
resp, err := s.client.R().
|
||||
SetQueryParamsFromValues(query).
|
||||
SetContext(ctx).
|
||||
SetResult(&result).
|
||||
SetPathParam("urlBase", s.urlBase).
|
||||
SetQueryParam("api_key", s.APIKey).
|
||||
Get("https://{urlBase}/geocoding/v1/search")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("geocoding get: %w", err)
|
||||
}
|
||||
|
||||
if !resp.IsSuccess() {
|
||||
return nil, parseError(resp)
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
|
@ -7,8 +7,8 @@ import (
|
|||
"github.com/google/go-querystring/query"
|
||||
)
|
||||
|
||||
// StructuredGeocodeRequest represents the query parameters for structured geocoding
|
||||
type StructuredGeocodeRequest struct {
|
||||
// RequestGeocodeStructured represents the query parameters for structured geocoding
|
||||
type RequestGeocodeStructured struct {
|
||||
// Address components
|
||||
Address *string `url:"address,omitempty" json:"address,omitempty"`
|
||||
Neighbourhood *string `url:"neighbourhood,omitempty" json:"neighbourhood,omitempty"`
|
||||
|
|
@ -24,7 +24,7 @@ type StructuredGeocodeRequest struct {
|
|||
BoundaryCircleLon *float64 `url:"boundary.circle.lon,omitempty"`
|
||||
BoundaryCircleRadius *float64 `url:"boundary.circle.radius,omitempty"`
|
||||
|
||||
BoundaryCountry []string `url:"boundary.country,omitempty,comma" json:"boundary.country,omitempty,comma"`
|
||||
BoundaryCountry []string `url:"boundary.country,omitempty,comma" json:"boundary.country,omitempty"`
|
||||
|
||||
BoundaryGid *string `url:"boundary.gid,omitempty" json:"boundary.gid,omitempty"`
|
||||
// Boundary parameters
|
||||
|
|
@ -38,13 +38,24 @@ type StructuredGeocodeRequest struct {
|
|||
FocusPointLng *float64 `url:"focus.point.lon,omitempty" json:",omitempty"`
|
||||
|
||||
// Other parameters
|
||||
Layers []string `url:"layers,omitempty,comma" json:"layers,omitempty,comma"`
|
||||
Sources []string `url:"sources,omitempty,comma" json:"sources,omitempty,comma"`
|
||||
Layers []string `url:"layers,omitempty,comma" json:"layers,omitempty"`
|
||||
Sources []string `url:"sources,omitempty,comma" json:"sources,omitempty"`
|
||||
Size *int `url:"size,omitempty" json:"size,omitempty"`
|
||||
Lang *string `url:"lang,omitempty" json:"lang,omitempty"`
|
||||
}
|
||||
|
||||
func (s *StadiaMaps) StructuredGeocode(ctx context.Context, req StructuredGeocodeRequest) (*GeocodeResponse, error) {
|
||||
func (r *RequestGeocodeStructured) SetBoundaryRect(xmin, ymin, xmax, ymax float64) {
|
||||
r.BoundaryRectMaxLat = &ymax
|
||||
r.BoundaryRectMinLat = &ymin
|
||||
r.BoundaryRectMaxLon = &xmax
|
||||
r.BoundaryRectMinLon = &xmin
|
||||
}
|
||||
func (r *RequestGeocodeStructured) SetFocusPoint(x, y float64) {
|
||||
r.FocusPointLat = &y
|
||||
r.FocusPointLng = &x
|
||||
}
|
||||
|
||||
func (s *StadiaMaps) GeocodeStructured(ctx context.Context, req RequestGeocodeStructured) (*GeocodeResponse, error) {
|
||||
// https://docs.stadiamaps.com/geocoding-search-autocomplete/structured-search/
|
||||
// curl "https://api.stadiamaps.com/geocoding/v1/search/structured?address=P%C3%B5hja%20pst%2027a®ion=Harju&country=EE&api_key=YOUR-API-KEY"
|
||||
var result GeocodeResponse
|
||||
|
|
@ -70,7 +81,3 @@ func (s *StadiaMaps) StructuredGeocode(ctx context.Context, req StructuredGeocod
|
|||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (sgr StructuredGeocodeRequest) endpoint() string {
|
||||
return "/v1/search/structured"
|
||||
}
|
||||
6
stadia/request.go
Normal file
6
stadia/request.go
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package stadia
|
||||
|
||||
type RequestGeocode interface {
|
||||
SetBoundaryRect(xmin, ymin, xmax, ymax float64)
|
||||
SetFocusPoint(x, y float64)
|
||||
}
|
||||
49
stadia/reverse_geocode.go
Normal file
49
stadia/reverse_geocode.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package stadia
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
)
|
||||
|
||||
type RequestReverseGeocode struct {
|
||||
Latitude float64 `url:"point.lat" json:"point.lat"`
|
||||
Longitude float64 `url:"point.lon" json:"point.lon"`
|
||||
|
||||
// Boundary circle parameters
|
||||
BoundaryCircleRadius *float64 `url:"boundary.circle.radius,omitempty"`
|
||||
BoundaryCountry []string `url:"boundary.country,omitempty"`
|
||||
BoundaryGID string `url:"boundary.gid,omitempty"`
|
||||
|
||||
// Other parameters
|
||||
Layers []string `url:"layers,omitempty,comma" json:"layers,omitempty"`
|
||||
Size *int `url:"size,omitempty" json:"size,omitempty"`
|
||||
Sources []string `url:"sources,omitempty,comma" json:"sources,omitempty"`
|
||||
}
|
||||
|
||||
func (s *StadiaMaps) ReverseGeocode(ctx context.Context, req RequestReverseGeocode) (*GeocodeResponse, error) {
|
||||
// https://docs.stadiamaps.com/geocoding-search-autocomplete/reverse-search/
|
||||
var result GeocodeResponse
|
||||
|
||||
query, err := query.Values(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reverse geocode query: %w", err)
|
||||
}
|
||||
//var api_error Error
|
||||
resp, err := s.client.R().
|
||||
SetQueryParamsFromValues(query).
|
||||
SetContext(ctx).
|
||||
SetResult(&result).
|
||||
SetPathParam("urlBase", s.urlBase).
|
||||
SetQueryParam("api_key", s.APIKey).
|
||||
Get("https://{urlBase}/geocoding/v2/reverse")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reverse geocoding get: %w", err)
|
||||
}
|
||||
|
||||
if !resp.IsSuccess() {
|
||||
return nil, parseError(resp)
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue