Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query all documents given coordinate and radius and understanding GFGeoHashQuery. #7

Open
levieggert opened this issue Sep 23, 2018 · 3 comments

Comments

@levieggert
Copy link

levieggert commented Sep 23, 2018

Hey first off, thanks a lot for this library. It is very handy.

I'm trying to better understand how to use GFGeoHashQuery in order to do my own querying against Firestore.

First, I'll run through what I am trying to accomplish and provide a code sample. Then, I will follow up with some questions.

  1. What I am trying to accomplish is, given a coordinate and radius, query all documents in Firestore that are within the radius of the given coordinate. I only need to query Firestore once because I will grab the user's current location and never ask for it again until the app is re-launched.

Here is some sample code for this.

let coordinate: CLLocationCoordinate2D = some-coordinate
let metersToMile: Double = 1609.34
let miles: Double = 50
let meters: Double = metersToMile * miles
        
let geoHashQueries: Set<AnyHashable> = GFGeoHashQuery.queries(forLocation: coordinate, radius: meters)
let geoHashQueriesArray: [AnyHashable] = Array(geoHashQueries) 

if let queryHash = geoHashQueriesArray.first as? GFGeoHashQuery
{
    let query: Query = self.eventsCollection.order(by: "g").whereField("g", isGreaterThanOrEqualTo: queryHash.startValue).whereField("g", isLessThanOrEqualTo: queryHash.endValue)
        
    query.getDocuments { (snapshot: QuerySnapshot?, error: Error?) in
                
        //map snapshot documents
    }
}

The main thing I notice is GFGeoHashQuery.queries(forLocation: coordinate, radius: meters) can return an array of geo hash queries with 0 or more objects.

  • Shouldn't it only return 1 geo hash?

  • If there are multiple geo hash objects, do I have to query against Firestore with each geo hash?

  • Can multiple geo hash objects return results from Firestore?

I appreciate any feedback you can give me. After looking through your code in GeoFirestore.swift I feel like I am on the right track here. Also what are your thoughts on implementing something similar to this in GeoFirestore?

Thanks

@theonlynick0430
Copy link
Member

theonlynick0430 commented Sep 25, 2018 via email

@donpironet
Copy link

I also have this problem. I just want to have all the documents that are in the radius.
Now the problem I see is 1 that I don't see in the observeNext that I have all the documents and 2 I need to perform an extra query for getting the document?

@vasquezdennisalon
Copy link

Has anyone been able to solve this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants