From e6fb16557fdc28d6b2d45080a258233c3254be48 Mon Sep 17 00:00:00 2001 From: Viktor Date: Thu, 23 Aug 2018 19:39:47 +0200 Subject: [PATCH] internal/geocode: use viewport if bounds is not defined The bounds response from google geo api is optional and for many searches not returned at all. Use viewport in those cases. Change-Id: Iaf0a055720fd6cc0a2c87e93b8e22315798a0b35 --- internal/geocode/geocode.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/internal/geocode/geocode.go b/internal/geocode/geocode.go index 16c715eaf..86e94e483 100644 --- a/internal/geocode/geocode.go +++ b/internal/geocode/geocode.go @@ -181,17 +181,14 @@ func decodeGoogleResponse(r io.Reader) (rects []Rect, err error) { return nil, err } for _, res := range resTop.Results { - if res.Geometry != nil && res.Geometry.Bounds != nil { - r := res.Geometry.Bounds - if r.NorthEast.Lat == 90 && r.NorthEast.Long == 180 && - r.SouthWest.Lat == -90 && r.SouthWest.Long == -180 { - // Google sometimes returns a "whole world" rect for large addresses (like "USA") - // so instead use the viewport in that case. - if res.Geometry.Viewport != nil { - rects = append(rects, *res.Geometry.Viewport) - } - } else { + if res.Geometry != nil { + if r := res.Geometry.Bounds; r != nil && !(r.NorthEast.Lat == 90 && r.NorthEast.Long == 180 && + r.SouthWest.Lat == -90 && r.SouthWest.Long == -180) { + // Google sometimes returns a "whole world" rect for large addresses (like "USA"), so we only + // use the Bounds when they exist and make sense. Otherwise we use the Viewport if available. rects = append(rects, *r) + } else if res.Geometry.Viewport != nil { + rects = append(rects, *res.Geometry.Viewport) } } }