From 7c4e6e236eaeb8c4587098afcb0dd8cdf57d10fa Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 5 May 2021 10:43:44 +0100 Subject: [PATCH] fix geocoding --- geocoding/handler/handler.go | 6 +++--- geocoding/handler/handler_test.go | 6 ------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/geocoding/handler/handler.go b/geocoding/handler/handler.go index 7397b60..3166801 100644 --- a/geocoding/handler/handler.go +++ b/geocoding/handler/handler.go @@ -24,7 +24,7 @@ type Geocoding struct { func (g *Geocoding) Lookup(ctx context.Context, req *pb.LookupRequest, rsp *pb.LookupResponse) error { // 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 { logger.Errorf("Error geocoding: %v", err) return ErrDownstream @@ -72,9 +72,9 @@ func (g *Geocoding) Reverse(ctx context.Context, req *pb.ReverseRequest, rsp *pb return nil } -func toString(a *pb.Address) string { +func toString(l *pb.LookupRequest) 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) if len(t) > 0 { comps = append(comps, t) diff --git a/geocoding/handler/handler_test.go b/geocoding/handler/handler_test.go index c06ca33..e2c1731 100644 --- a/geocoding/handler/handler_test.go +++ b/geocoding/handler/handler_test.go @@ -152,12 +152,6 @@ func TestGeocoding(t *testing.T) { if len(tc.Address.LineTwo) > 0 { 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{ Address: address, Postcode: tc.Address.Postcode,