Return results only if they are within radius

How can I display results only within a defined radius. Right now I have my radius set, but because I do not have very much data around me, I think Algolia is returning everything. I am trying to perform a search that returns only what is close to the user. If that makes sense. I am using swift and here is my code:

func updateSearchResults() {
    query.aroundLatLng = LatLng(lat: userLat ,lng: userLng)
    query.minimumAroundRadius = 10
    query.query = ""
    let curSearchId = searchId
    
    self.businessIndex.search(self.query, completionHandler: {
        (data, error) in
        
        if curSearchId <= self.displayedSearchId || error != nil {
            print("problem #1")
            print(error?.localizedDescription ?? "Error 1")
            return // Newest query already displayed or error
        }
        
        // Decode JSON
        guard let hits = data!["hits"] as? [[String: AnyObject]] else { return }
        guard let nbPages = data!["nbPages"] as? UInt else { return }
        self.nbPages = nbPages
        
        var tmp = [checkInBusiness]()
        for hit in hits {
            tmp.append(checkInBusiness(json: hit))
            
        }
        
        //Reload view with the new data
        self.checkInSearch = tmp
        print(tmp)
        DispatchQueue.main.async() {
            
            self.tableView.reloadData()
            
       
            
        }
    })
    self.searchId += 1
    
}

I figured it out. query.aroundRadius = .explicit(300)
the .explicit threw me off

1 Like