Skip to content

Commit 07eb947

Browse files
committed
Insist on a location for POIs.
Signed-off-by: Katharine Berry <[email protected]>
1 parent fcae1cb commit 07eb947

File tree

1 file changed

+11
-3
lines changed
  • service/assistant/functions

1 file changed

+11
-3
lines changed

service/assistant/functions/poi.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ func searchPoi(ctx context.Context, quotaTracker *quota.Tracker, args interface{
113113
Lat: coords.Lat,
114114
}
115115
}
116+
if location == nil {
117+
span.AddField("error", "no location provided")
118+
return Error{Error: "Either the user must enable location in settings, or an explicit location parameter must be provided"}
119+
}
116120

117121
placeService, err := places.NewService(ctx)
118122
if err != nil {
@@ -158,9 +162,13 @@ func searchPoi(ctx context.Context, quotaTracker *quota.Tracker, args interface{
158162
var pois []POI
159163
var attributions map[string]any
160164
for _, place := range results.Places {
161-
distMiles, distKm := haversine.Distance(
162-
haversine.Coord{location.Lat, location.Lon},
163-
haversine.Coord{place.Location.Latitude, place.Location.Longitude})
165+
var distMiles, distKm float64
166+
userLocation := query.LocationFromContext(ctx)
167+
if userLocation != nil && place.Location != nil {
168+
distMiles, distKm = haversine.Distance(
169+
haversine.Coord{userLocation.Lat, userLocation.Lon},
170+
haversine.Coord{place.Location.Latitude, place.Location.Longitude})
171+
}
164172
poi := POI{
165173
Name: place.DisplayName.Text,
166174
Address: place.ShortFormattedAddress,

0 commit comments

Comments
 (0)