GeoSearch ничего не возвращает - PullRequest
0 голосов
/ 08 мая 2019

Итак, я работаю над переносом своей функциональности geoSearch с GeoFire на Algolia, потому что есть и другие варианты, такие как фильтрация и многие другие вещи, которые могут сделать жизнь намного проще.

В настоящее время я использую его для поиска событий, ближайших к местоположению пользователя. Как сказано в документации (https://www.algolia.com/doc/guides/managing-results/refine-results/geolocation/) Я добавил этот атрибут

"_ geoloc": { «широта»: 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"
}

Если кто-нибудь может увидеть, где я ошибся, пожалуйста, дайте мне знать !!!

...