0
votes

I'm using Firebase with GeoFire 3.0 Cocoapod in my Swift App to populate a map with markers all over the world. Here is the code to perform the circle query to get the markers within the area currently displayed on the map:

        dbRef = Database.database().reference()
        let geoRef = GeoFire(firebaseRef: dbRef.child("markers"))
        let center = CLLocation(latitude: currentLocation.latitude, longitude: currentLocation.longitude)
        print("Center: "," Lat: ",currentLocation.latitude," Long: ",currentLocation.longitude )
        let circleQuery = geoRef.query(at: center, withRadius: 100)
        circleQuery.observe(.keyEntered, with: { key, location in
            print("key: ",key,"Location: ",location)
            let markerKey = key
            let markerLat = location.coordinate.latitude
            let markerLong = location.coordinate.longitude
            //read "verified" flag from firebase record "key"
            self.dbRef.child(markerKey).observeSingleEvent(of: .value, with: { (snapshot) in
                let value = snapshot.value as? NSDictionary
                let verified = value?["verified"] as? Bool
                print("key: ",key,"Location: ",location,"verified: ",verified as Any)
                ...
            })
         })

When the circle query is expanded by the user zooming out to display the map of the entire world (radius of 8000 Km (4791 MI)), the query aborts with an NSException.

The Xcode debugger shows GeoFire has calculated a latitude of 105.9793939... and longitude of -112.05707936...

Geofire should restrict the latitude at +/- 90 and the longitude at +/- 180 and in that case all GeoFire data should be returned from the Query.

Here is a screenshot of the error in Xcode: Xcode Error Screenshot

Has anyone else seen this issue and/or found a solution?

1

1 Answers

0
votes

Since GeoFire clearly does not limit the latitude and longitude in the way you want it to, you have two options

  1. Report an issue on the GeoFire repo, and possibly propose a PR yourself.
  2. Limit the values to the ranges you want in your own application code.

I'd suggest going with the second approach, since you'll want/need to show that you clipped/restricted the range in the UI anyway.