GeoSearch不返回任何内容

时间:2019-05-08 15:59:23

标签: ios swift algolia

所以我正在努力将我的geoSearch功能从GeoFire迁移到Algolia,因为过滤方面还有更多选择,还有许多其他事情可以使生活变得更加轻松。

我目前正在使用它来搜索距离用户位置最近的事件。就像文档所说的(https://www.algolia.com/doc/guides/managing-results/refine-results/geolocation/)一样,我添加了此属性

  

“ _ geoloc”:{       “ lat”:37.7909427,       “ lng”:-122.4084994     }

使地理搜索成为可能。之后,我使用SwiftLocation来获取用户当前地理查询/搜索的经度和纬度。文档说这样做(https://www.algolia.com/doc/api-reference/api-parameters/aroundLatLng/

let query = Query(query: "query")
query.aroundLatLng = LatLng(lat: 40.71, lng: -74.01)

index.search(query, completionHandler: { (res, error) in
  print(res)
})

我用这段代码完成了

static func fetchEventsFromAlgolia(completion: @escaping (String) -> Void) {

    let client = Client(appID: Algolia.appID, apiKey: Algolia.apiKey)
    let index = client.index(withName:indice.events)
    let query = Query(query: "query")

    LocationService.getUserLocation { (currentLocation) in

        guard let latitude = currentLocation?.coordinate.latitude else {
            completion("error finding latitude")
            return
        }

        guard let longitude = currentLocation?.coordinate.longitude else {
            completion("error finding longitude")
            return
        }

        query.aroundLatLng = LatLng(lat: latitude, lng:longitude )
        query.aroundRadius = .all
        index.search(query, completionHandler: { (res, err) in
            if err == nil {
                guard let res = res else {
                    completion("error with res unwrapping")
                    return
                }


                let data = res["hits"]! as! [NSDictionary]
                print("Result: \(data.count)")
                print(res.description)
                completion("success events should have been printed")
            }else {
                completion(err as! String)
            }
        })


    }

}

但是,当我将结果打印到终端时,我什么也没得到。好像查询成功,但结果却没有回来。

这是针对我的具体情况的事件条目之一,在阿尔及利亚如何显示

{
  "attend:count": 6,
  "event:category": "concert",
  "event:city": "San Francisco",
  "event:date": {
    "end:date": "05/11/2019",
    "end:time": "11:35 PM",
    "start:date": "04/19/2019",
    "start:time": "10:55 PM"
  },
  "event:datetime": {
    "end": 1557632100,
    "start": 1555728900
  },
  "event:description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
  "event:imageURL": "https://firebasestorage.googleapis.com/v0/b/eventful-3d558.appspot.com/o/event_flyers%2Flilpump.jpg?alt=media&token=40c310d2-fe1e-49c4-b3a6-7419e6ef7ddd",
  "event:name": "lil pump performance",
  "event:price": 0,
  "event:promo": "https://firebasestorage.googleapis.com/v0/b/eventful-3d558.appspot.com/o/event_promo_vid%2FBEVT%2FTravis%20Scott_%20Houston%20Birds%20Eye%20View%20Tour%20Promo.mp4?alt=media&token=6d27d76e-281e-4083-a0ff-dbe2f25703e7",
  "event:state": "CA",
  "event:street:address": "2 Stockton St",
  "event:zip": 94108,
  "host_user": [
    "XwOBrK6zJXRG7wltV1QvoVXi6Jg1"
  ],
  "tags": [
    "hip hop",
    "concert"
  ],
  "_geoloc": {
    "lat": 37.7909427,
    "lng": -122.4084994
  },
  "objectID": "LPP"
}

如果有人可以看到我出了错,请告诉我!!!

0 个答案:

没有答案