mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
fix geocoding
This commit is contained in:
@@ -24,7 +24,7 @@ type Geocoding struct {
|
|||||||
|
|
||||||
func (g *Geocoding) Lookup(ctx context.Context, req *pb.LookupRequest, rsp *pb.LookupResponse) error {
|
func (g *Geocoding) Lookup(ctx context.Context, req *pb.LookupRequest, rsp *pb.LookupResponse) error {
|
||||||
// query google maps
|
// query google maps
|
||||||
results, err := g.Maps.Geocode(ctx, &maps.GeocodingRequest{Address: req.Address})
|
results, err := g.Maps.Geocode(ctx, &maps.GeocodingRequest{Address: toString(req)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Error geocoding: %v", err)
|
logger.Errorf("Error geocoding: %v", err)
|
||||||
return ErrDownstream
|
return ErrDownstream
|
||||||
@@ -72,9 +72,9 @@ func (g *Geocoding) Reverse(ctx context.Context, req *pb.ReverseRequest, rsp *pb
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func toString(a *pb.Address) string {
|
func toString(l *pb.LookupRequest) string {
|
||||||
var comps []string
|
var comps []string
|
||||||
for _, c := range []string{a.LineOne, a.LineTwo, a.City, a.Postcode, a.Country} {
|
for _, c := range []string{l.Address, l.City, l.Postcode, l.Country} {
|
||||||
t := strings.TrimSpace(c)
|
t := strings.TrimSpace(c)
|
||||||
if len(t) > 0 {
|
if len(t) > 0 {
|
||||||
comps = append(comps, t)
|
comps = append(comps, t)
|
||||||
|
|||||||
@@ -152,12 +152,6 @@ func TestGeocoding(t *testing.T) {
|
|||||||
if len(tc.Address.LineTwo) > 0 {
|
if len(tc.Address.LineTwo) > 0 {
|
||||||
address = fmt.Sprintf("%s, %s", address, tc.Address.LineTwo)
|
address = fmt.Sprintf("%s, %s", address, tc.Address.LineTwo)
|
||||||
}
|
}
|
||||||
if len(tc.Address.Postcode) > 0 {
|
|
||||||
address = fmt.Sprintf("%s, %s", address, tc.Address.Postcode)
|
|
||||||
}
|
|
||||||
if len(tc.Address.Country) > 0 {
|
|
||||||
address = fmt.Sprintf("%s, %s", address, tc.Address.Country)
|
|
||||||
}
|
|
||||||
err = h.Lookup(context.TODO(), &pb.LookupRequest{
|
err = h.Lookup(context.TODO(), &pb.LookupRequest{
|
||||||
Address: address,
|
Address: address,
|
||||||
Postcode: tc.Address.Postcode,
|
Postcode: tc.Address.Postcode,
|
||||||
|
|||||||
Reference in New Issue
Block a user