GeoFire query on User location

后端 未结 3 1399
灰色年华
灰色年华 2020-12-09 13:57

I\'m quite new to work with Firebase and its location library, GeoFire. Currently I\'m facing some problem when structuring my data.

At the moment my db is something

相关标签:
3条回答
  • 2020-12-09 14:39

    Seems that there is an issue when setting up the GFEventType. That will be resolved it seems on the next version of GeoFire 1.3, for now you can do this...

    let geoFire = GeoFire(firebaseRef: ref)
    
    var allKeys = [String:CLLocation]()
    
    let query = geoFire.queryAtLocation(coordinates, withRadius: 0.2)
    print("about to query")
    query.observeEventType(GFEventType.init(0), withBlock: {(key: String!, location: CLLocation!) in
        print("Key: \(key), location \(location.coordinate.latitude)")
        allKeys [key] = location
    })
    

    As you can see GFEventType.init(0)... that maps to the three types of enums that are not correctly mapped on GeoFire in Swift for some reason.

    0 讨论(0)
  • 2020-12-09 14:40

    To save all your records that match the query you have to store all of using something like:

        var allKeys = [String:CLLocation]()
    
        circleQuery.observeEventType(GFEventTypeKeyEntered, withBlock: {
            (key: String!, location: CLLocation!) in
    
            allKeys [key]=location
          }
    

    and then use

        circleQuery.observeReadyWithBlock({
            print("All initial data has been loaded and events have been fired!")
        })
    
    0 讨论(0)
  • 2020-12-09 14:43

    For GeoFire you must keep a segment in the tree that contains just the geolocation and then you have another segment in the tree that contains the other information about the items.

    user_locations
      uid1:
        g: xxxx
        l:
          0: xxx
          1: xxx
      uid2:
        g: xxxx
        l:
          0: xxx
          1: xxx
    user_profiles:
      uid1:
        name: "giacavicchioli"
      uid2:
        name: "Frank van Puffelen"
    

    Also see: Query firebase data linked to GeoFire

    0 讨论(0)
提交回复
热议问题