feat: Added ability to get address from coordinates
This commit is contained in:
parent
ab7e9437f3
commit
a3bb529fe4
30
api/geolocate/geolocate.go
Normal file
30
api/geolocate/geolocate.go
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package geolocate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Requester provides transport level API calls.
|
||||||
|
Requester interface {
|
||||||
|
// Post makes a POST API call. Assumes sending json-encoded params in a request body.
|
||||||
|
Post(ctx context.Context, apiMethod string, params, result interface{}) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Api provides suggestion API.
|
||||||
|
Api struct {
|
||||||
|
Client Requester
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddressByGeolocate try to return suggest addresses by params
|
||||||
|
// see documentation on:https://dadata.ru/api/geolocate/
|
||||||
|
func (a *Api) AddressByGeolocate(ctx context.Context, params *RequestParams) (ret []*AddressGeolocateSuggestion, err error) {
|
||||||
|
var result = &AddressGeolocateResponse{}
|
||||||
|
err = a.Client.Post(ctx, "geolocate/address", params, result)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ret = result.Suggestions
|
||||||
|
return
|
||||||
|
}
|
27
api/geolocate/model.go
Normal file
27
api/geolocate/model.go
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package geolocate
|
||||||
|
|
||||||
|
import "github.com/ekomobile/dadata/v2/api/model"
|
||||||
|
|
||||||
|
type (
|
||||||
|
// RequestParams Request struct
|
||||||
|
// full documentation https://confluence.hflabs.ru/pages/viewpage.action?pageId=808583277
|
||||||
|
RequestParams struct {
|
||||||
|
Lat string `json:"lat"` // geographic latitude
|
||||||
|
Lon string `json:"lon"` // geographic longitude
|
||||||
|
Count string `json:"count,omitempty"` // number of results (max 20)
|
||||||
|
RadiusMeters string `json:"radius_meters,omitempty"` // search radius in metres (max. 1000)
|
||||||
|
Language string `json:"language,omitempty"` // in which language to return the result (ru / en)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressGeolocateSuggestion api response for address
|
||||||
|
AddressGeolocateSuggestion struct {
|
||||||
|
Value string `json:"value"`
|
||||||
|
UnrestrictedValue string `json:"unrestricted_value"`
|
||||||
|
Data *model.Address `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressGeolocateResponse result slice for address suggestions
|
||||||
|
AddressGeolocateResponse struct {
|
||||||
|
Suggestions []*AddressGeolocateSuggestion `json:"suggestions"`
|
||||||
|
}
|
||||||
|
)
|
|
@ -92,7 +92,7 @@ type (
|
||||||
// full documentation https://confluence.hflabs.ru/pages/viewpage.action?pageId=222888017
|
// full documentation https://confluence.hflabs.ru/pages/viewpage.action?pageId=222888017
|
||||||
BoundValue string
|
BoundValue string
|
||||||
|
|
||||||
// Address base struct for datdata.Address
|
// Address base struct for datdata.AddressByGeolocate
|
||||||
Address struct {
|
Address struct {
|
||||||
Source string `json:"source"` // Исходный адрес одной строкой
|
Source string `json:"source"` // Исходный адрес одной строкой
|
||||||
Result string `json:"result"` // Стандартизованный адрес одной строкой
|
Result string `json:"result"` // Стандартизованный адрес одной строкой
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/ekomobile/dadata/v2/api/clean"
|
"github.com/ekomobile/dadata/v2/api/clean"
|
||||||
|
"github.com/ekomobile/dadata/v2/api/geolocate"
|
||||||
"github.com/ekomobile/dadata/v2/api/profile"
|
"github.com/ekomobile/dadata/v2/api/profile"
|
||||||
"github.com/ekomobile/dadata/v2/api/stat"
|
"github.com/ekomobile/dadata/v2/api/stat"
|
||||||
"github.com/ekomobile/dadata/v2/api/suggest"
|
"github.com/ekomobile/dadata/v2/api/suggest"
|
||||||
|
@ -15,6 +16,7 @@ const (
|
||||||
EndpointURL = "https://dadata.ru/api/v2/"
|
EndpointURL = "https://dadata.ru/api/v2/"
|
||||||
// EndpointURLSuggest is a suggestion API endpoint.
|
// EndpointURLSuggest is a suggestion API endpoint.
|
||||||
EndpointURLSuggest = "https://suggestions.dadata.ru/suggestions/api/4_1/rs/"
|
EndpointURLSuggest = "https://suggestions.dadata.ru/suggestions/api/4_1/rs/"
|
||||||
|
|
||||||
// EndpointURLClean is a cleaner API endpoint.
|
// EndpointURLClean is a cleaner API endpoint.
|
||||||
EndpointURLClean = "https://cleaner.dadata.ru/api/v1/"
|
EndpointURLClean = "https://cleaner.dadata.ru/api/v1/"
|
||||||
)
|
)
|
||||||
|
@ -58,6 +60,12 @@ func NewSuggestApi(opts ...client.Option) *suggest.Api {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewGeolocateApi(opts ...client.Option) *geolocate.Api {
|
||||||
|
return &geolocate.Api{
|
||||||
|
Client: client.NewClient(endpointURLSuggest, opts...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewProfileApi provides profile related API.
|
// NewProfileApi provides profile related API.
|
||||||
func NewProfileApi(opts ...client.Option) *profile.Api {
|
func NewProfileApi(opts ...client.Option) *profile.Api {
|
||||||
return &profile.Api{
|
return &profile.Api{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user