geofire-objc icon indicating copy to clipboard operation
geofire-objc copied to clipboard

Not a valid geo location for a huge radius

Open zgosalvez opened this issue 8 years ago • 18 comments

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.

zgosalvez avatar Sep 11 '16 03:09 zgosalvez

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!

JPROFFICIAL avatar Sep 13 '16 00:09 JPROFFICIAL

+1

b992 avatar Oct 08 '16 09:10 b992

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 avatar Dec 16 '16 11:12 ahaverty

@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)

zgosalvez avatar Mar 11 '17 01:03 zgosalvez

@ahaverty did found a solution ?

Ekhoo avatar Mar 29 '17 20:03 Ekhoo

Thanks @zgosalvez ! That's progress @ekhoo no other than limiting the distance. It's strange, as geofire android supports a full globe 🤔

ahaverty avatar Mar 29 '17 21:03 ahaverty

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?

grantkemp avatar Apr 09 '17 20:04 grantkemp

Anyone found a solution on IOS for this, where the entire world is covered?

ThorvaldAagaard avatar Nov 26 '17 13:11 ThorvaldAagaard

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 avatar Feb 16 '18 05:02 farzaa

@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

beatTheSystem42 avatar May 14 '18 14:05 beatTheSystem42

+FratGodLordOfBeer Hey...so this keeps the radius as 10000 units even though you're dividing rad by 1000? that is odd.

VeganEngineer avatar Jul 07 '18 19:07 VeganEngineer

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

LanceSamaria avatar Nov 03 '18 14:11 LanceSamaria

@zgosalvez @LanceSamaria @Primate92587 @FratGodLordOfBeer @farzaa

Any solution for this other than limiting the radius?

vaibhav-jhaveri-ds avatar Nov 19 '19 07:11 vaibhav-jhaveri-ds

@vaibhav-jhaveri-ds, the team decided to switch queries to Algolia, which allows for more complex queries on top of geo location.

zgosalvez avatar Nov 19 '19 11:11 zgosalvez

@zgosalvez Which product do you use in place of GeoFire?

vaibhav-jhaveri-ds avatar Nov 19 '19 11:11 vaibhav-jhaveri-ds

@vaibhav-jhaveri-ds, check out Algolia's Search API. More here: https://www.algolia.com/doc/guides/managing-results/refine-results/geolocation/#geo-search

zgosalvez avatar Nov 19 '19 11:11 zgosalvez

@morganchen12 Will there be any solution for this particular issue?

vaibhav-jhaveri-ds avatar Dec 13 '19 12:12 vaibhav-jhaveri-ds

any update on this?

nicooliver avatar Jan 02 '24 14:01 nicooliver