geofire-objc
geofire-objc copied to clipboard
Not a valid geo location for a huge radius
I'm making a global app that requires schools to be sorted from nearest to farthest, based on the user's location. To do this, I set geoFire.queryAtLocation(location, withRadius: 40075)
This causes a precision error ('Precision must be less than 23!'
) which I don't understand. So I reduced the radius to 4000. This time I'm getting a 'Not a valid geo location: [100.062421,-21.955856]'
error. I hard coded the user's location to be somewhere in Iceland CLLocation(latitude: 63.8875517, longitude: -21.9558564)
It seems that this error shows up when the radius hits one of the poles, in this case the north pole, since I don't get the same error when I change the user's location to somewhere nearer the equator.
Hey @zgosalvez, I had the same type of thing happen where I had to query a large radius, and what I ended up doing was using the GFRegionQuery
. This fixed this issue from happening to me. If I am off and that is not the answer you're looking for, take a look at https://github.com/firebase/geofire-objc/issues/27. Hope it helps!
+1
I'm hitting the same issues here in Ireland. The iOS app reviewers in Cupertino, CA are unable to view my locations and are failing the app review. I'm trying to set the radius to global but hitting the same precision error @zgosalvez hit. I need a quick fix before the reviews close for christmas, did you make any progress @zgosalvez , the GFRegionQuery @JPROFFICIAL suggested seems suitable for use with a map, but I'm only using the user's current location.
@ahaverty Sorry for not getting back to you sooner. This is the only time I got to go back to my project. I used region query instead of radius. This gives a bigger section of the globe without extending beyond acceptable values. The only drawback is that it still isn't the entire globe.
let span = MKCoordinateSpanMake(90 - userCurrentLocation.coordinate.latitude, 180 - userCurrentLocation.coordinate.longitude)
let region = MKCoordinateRegionMake(userCurrentLocation.coordinate, span)
regionQuery = geoFire!.query(with: region)
@ahaverty did found a solution ?
Thanks @zgosalvez ! That's progress @ekhoo no other than limiting the distance. It's strange, as geofire android supports a full globe 🤔
This is a breaking feature for one of my apps. Thanks for the span idea though. @zgosalvez why did you use 90 - and 180 in to calculate the span?
Anyone found a solution on IOS for this, where the entire world is covered?
Any updates on this? When I run this code:
let loc = CLLocation(latitude: 28.548529, longitude: 81.194081)
guard let circleQuery = geofire.query(at: loc, withRadius: 10000) else { return }
I get the error
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Precision must be less than 23!'
I want to be able to query a region of 10,000 m around a user. The fix above using MKCoordinateSpanMake
doesn't seem to fix this and will just query everything.
@farzaa I ran into this issue, but was able to overcome it simply by dividing my radius by 1000. I noticed in the GeoFire usage example they were representing 600 meters as 0.6 when initializing the circle query object.
let loc = CLLocation(latitude: 28.548529, longitude: 81.194081)
let rad = 10000
let circleQuery = geoFire.query(at: loc, withRadius: rad / 1000)
hope this helps.
https://github.com/firebase/geofire-objc
+FratGodLordOfBeer Hey...so this keeps the radius as 10000 units even though you're dividing rad by 1000? that is odd.
Follow this guy's answer to get convert your miles to meters
1 mile is 1609.344 meters
To have your query coverage area match what's on your mapView you have double the number of miles then multiply it by meters
For eg. if the user choose 30 miles
let result = (30 * 2) * 1609.344
Use MKCoordinateRegionMakeWithDistance()
to set your location and plug the result from above into it then use GeoFire's .query(with: region)
to run the query
Basically set the region MKCoordinateRegionMakeWithDistance()
into the .query(with: region)
// 1.
let searchRegion = MKCoordinateRegionMakeWithDistance(usersLocation.coordinate, result, result)
// 2.
geoFire.query(with: searchRegion)
For a more detailed answer Here's my SO question and answer
@zgosalvez @LanceSamaria @Primate92587 @FratGodLordOfBeer @farzaa
Any solution for this other than limiting the radius?
@vaibhav-jhaveri-ds, the team decided to switch queries to Algolia, which allows for more complex queries on top of geo location.
@zgosalvez Which product do you use in place of GeoFire?
@vaibhav-jhaveri-ds, check out Algolia's Search API. More here: https://www.algolia.com/doc/guides/managing-results/refine-results/geolocation/#geo-search
@morganchen12 Will there be any solution for this particular issue?
any update on this?