fix geocoding

This commit is contained in:
Asim Aslam
2021-05-05 10:43:44 +01:00
parent 5894e0a994
commit 7c4e6e236e
2 changed files with 3 additions and 9 deletions

View File

@@ -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)

View File

@@ -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,