I am trying to implement infinite scrolling by expanding the radius of my GeoFire
query by 5kms so I can get the next set of keys. But my GeoFire
query is returning duplicates as it is picking up the keys found within the first 5kms in addition to the next 5kms so-on and so-on...
I was under the impression that it should only return the new keys found within the updated radius, have I missed something?
Console output showing duplicate keys found at 10kms then 15kms radius:
我的geoQuery
:
let geoQuery = GeoFire(firebaseRef: DB_BASE.child("venues-location")).query(at: CLLocation(), withRadius: 1)
我的fetchVenueNearby
函数:
func fetchVenueNearby(deviceLocation: CLLocation, radius: Double, handler: @escaping (Venue) -> ()) {
geoQuery.center = deviceLocation
geoQuery.radius = radius
geoQuery.observe(.keyEntered) { (key: String!, venueLocation: CLLocation!) in
print ("FOUND KEY: ", key)
self.REF_VENUES.child(key).observeSingleEvent(of: .value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String : Any] {
//parse snapshot code here….
}//end if-let
})//end observeSingleEvent
}//end geofire query observe
}//end func
这是我的loadMoreVenues
函数,当前用于测试我的地理位置查询
func loadMoreVenus() {
radius += 5
print("radius = \(radius)")
DataService.run.fetchVenueNearby(deviceLocation: currentLocation, radius: radius) { (venue) in
print("venue: \(venue.venueID)")
}
}//end func
答案 0 :(得分:0)
您需要过滤掉已经存在的结果。
当您使用新参数 + 5km 请求新结果时,它将向您返回新结果,您必须比较已有的结果并将其从结果中删除。
但是我对GeoFire
并不了解很多。
更好的选择是基于获取的最新位置作为起点,而不是用户当前的位置来请求最新的结果,而无需进行过滤