gpt4 book ai didi

ios - 在表格 View 中列出附近的 GeoFire 位置

转载 作者:行者123 更新时间:2023-11-30 13:31:30 35 4
gpt4 key购买 nike

目前,如下面的代码所示,我的表格 View 显示 Firebase 中的所有内容。如何将列表限制为附近的内容?

DataService.dataService.BUSINESS_REF.observeEventType(.Value, withBlock: { snapshot in

// A snapshot of the businesses data

self.businesses = []

if let snapshots = snapshot.children.allObjects as? [FDataSnapshot] {

for snap in snapshots {

// Make business array for the tableview
if let postDictionary = snap.value as? Dictionary<String, AnyObject> {

let key = snap.key
let business = Business(key: key, dictionary: postDictionary)

// Show newest business first
self.businesses.insert(business, atIndex: 0)
}
}
}

// Update the table when there is new data

self.searchTableView.reloadData()
})

我是 iOS 编程新手,上面的代码来自教程,我意识到我需要使用 GeoFire 的 GFQuery 对象,但我只是不知道将其放在代码中的位置。提前致谢!

最佳答案

想通了。希望有人能提出更好的方法来做到这一点。

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

firebase = Firebase(url:"https://myapp.firebaseio.com/")
geoFire = GeoFire(firebaseRef: firebase!.childByAppendingPath("geo"))

let userLocation:CLLocationCoordinate2D = (locationManager.location?.coordinate)!
let center = CLLocation(latitude: userLocation.latitude, longitude: userLocation.longitude)
let span = MKCoordinateSpanMake(0.0125, 0.0125)
let region = MKCoordinateRegionMake(center.coordinate, span)
let regionQuery = geoFire?.queryWithRegion(region)

UIApplication.sharedApplication().networkActivityIndicatorVisible = true

regionQuery!.observeEventType(GFEventTypeKeyEntered, withBlock: { (key: String!, location: CLLocation!) in

// Check for changes in Firebase database
DataService.dataService.BUSINESS_REF.queryOrderedByKey().queryEqualToValue(key).observeEventType(.Value, withBlock: { snapshot in

if let snapshots = snapshot.children.allObjects as? [FDataSnapshot] {

for snap in snapshots {

if let postDictionary = snap.value as? Dictionary<String, AnyObject> {

//let key = snap.key
let business = Business(key: key, dictionary: postDictionary)

self.businesses.insert(business, atIndex: 0)

}
}
}

self.searchTableView.reloadData()

})
})
}

关于ios - 在表格 View 中列出附近的 GeoFire 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36530484/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com