Skip to content

Instantly share code, notes, and snippets.

@loic-sharma
Created September 12, 2015 18:00
Show Gist options
  • Save loic-sharma/823f5377c227481cce20 to your computer and use it in GitHub Desktop.
Save loic-sharma/823f5377c227481cce20 to your computer and use it in GitHub Desktop.
GeoFire example
func relevantEventsForLocation(location: CLLocation, withBlock: ([Event]) -> ()) {
let root = Firebase(url: "https://pikapic.firebaseio.com")
let geoFire = GeoFire(firebaseRef: root)
var circleQuery = geoFire.queryAtLocation(location, withRadius: 0.6)
let span = MKCoordinateSpanMake(0.001, 0.001)
let region = MKCoordinateRegionMake(location.coordinate, span)
var query = geoFire.queryWithRegion(region)
var keys = Array<String>()
var events = Array<Event>()
query.observeEventType(GFEventTypeKeyEntered, withBlock: { (key: String!, location: CLLocation!) in
keys.append(key)
})
query.observeReadyWithBlock({
query.removeAllObservers()
// TODO convert keys into events.
// Call withBlock
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment