Retrieving Keys From GeoFire within Radius in Swift
Asked Answered
C

1

3

I have the following Firebase Database JSON data structure:

{
  "Post List" : {
    "-KUlvg8mCEGfY5ZSKCou" : {
      "addedByUser" : "7llQbPdy2NV7aO337h7ap0qLOhC3",
      "content" : "Post1",
      "cost" : "$450",
      "duration" : "Daily",
      "latitude" : "25.0879721592719",
      "longitude" : "55.1487715855458",
      "number" : "01234567890",
      "timestamp" : "Posted on: Sun 23 Oct"
    }
  },
  "Post Locations" : {
    "-KUlvg8mCEGfY5ZSKCou" : {
      ".priority" : "thrnwznh58",
      "g" : "thrnwznh58",
      "l" : [ 25.0879721592719, 55.1487715855458 ]
    }
  },
  "User Locations" : {
    "7llQbPdy2NV7aO337h7ap0qLOhC3" : {
      ".priority" : "thrnwypqu9",
      "g" : "thrnwypqu9",
      "l" : [ 25.0829547120321, 55.1505315855337 ]
    }
  }
}

I am looking to have a GeoFire query which will return all the keys [FIRAutoID's] within a radius of 1KM, for e.g. of "User Locations" these Posts are static and once the user location is set it will also be fixed. From the radius query result I am expecting to return "-KUlvg8mCEGfY5ZSKCou" so I can then make a reference the Post Details. Hope this makes sense. Many thanks, D. Cant find much online about GeoFire... looks like its still in the initial stages?...

Cide answered 23/10, 2016 at 15:35 Comment(0)
C
4

Figured it out

func geoFireQuery() {

        let circleQuery = geoFire.query(at: self.myLocation, withRadius: 0.5)

        _ = circleQuery!.observe(.keyEntered, with: { (key: String?, location: CLLocation?) in

        print (key!)

    })

    circleQuery?.observeReady({
        print("All initial data has been loaded and events have been fired!")

    })

}

this seems to be giving me what I need. Now to reference those keys to the other part of the FBDB. :)

Cide answered 27/10, 2016 at 10:6 Comment(2)
Is it possible in Javascript? To search keys (list of keys) of near by static(fixed) locations - which are pre-added in firebase datastore. Note: not using 'key_entered' because 'key_entered' only fires when new or position updated. What about previously added locations but coming under given radius. How is it possible??Salamone
This works but for some reason I am getting an arbitrary radius limit of 23 'Precision must be less than 23!' I'm guessing that is 23km but I'm not sure why the guys at geoFire went for that number, and why limit it at all.Budding

© 2022 - 2024 — McMap. All rights reserved.