Search code examples
firebaseswift4observersgeofire

Swift 4 and Geofire: dealing with invalid geolocation error


I am using the swift 4 language and geofire library to find points on the map within 3000 km of where I am. When the query encounters the latitude point 90,500 and longitude 100,000 the following error appears: "Not a valid geo location". The crash happens in the "query.observe(.keyEntered" line

query? = geoFire.query (at: self.currentLocation.newLocation !, withRadius: self.distance) {
    //code
}
//The crash happens on this line:
var queryHandler = query.observe(.keyEntered, with: {(key, location) in
    //Code
})

My question is, how can I handle this kind of error? Do I need to remove all incorrect coordinates from the database? Apparently the function "observe(.keyEntered" does not allow to handle exceptions. I would like to handle the exceptions without the app breaking


Solution

  • It seems like you're hitting the problem described in this issue on the Github repo: https://github.com/firebase/geofire-objc/issues/64

    From what I see there, the only option is to reduce the radius of the query.