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