Code Monkey home page Code Monkey logo

geofirestore-ios's People

Contributors

basementaspirations avatar dhruvshah1214 avatar mainto avatar obstructer avatar progn avatar ryanmdoyle avatar theonlynick0430 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

geofirestore-ios's Issues

Package.swift doesn't exist

I'm trying to add the package from: https://github.com/imperiumlabs/GeoFirestore-iOS using the File -> Add Packages in Xcode 14 but keep getting this error:

error project: the package manifest at '/Package.swift' cannot be accessed (/Package.swift doesn't exist in file system)

I've used exact version and to next major version but they result in the same error. I've just updated to Xcode 14, I don't know if its an issue with the Xcode install or an issue retreiving the package. Any idea?

Compilation Error

I am getting compilation error "Type of expression is ambiguous without more context " in line 378 of "Geofirestore.swift" file.
Code : var toDelete = (Set().union(oldQueries))
Xcode version : 9.2

Thank you!

Query all documents given coordinate and radius and understanding GFGeoHashQuery.

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

How to fetch documents around a certain location

Hello,

This might be a simple question but I'm having a hard time trying to figure out how to do this.

I'm developing an iOS app which transmits user's last known location periodically. My Firebase setup looks like this.

Screenshot 2020-05-18 at 18 12 28

It has a users collection. Each user has the aforementioned last location coordinate.

What I'm trying to do now is, given a location and a radius, fetch the set of users who fall within that radius.

I know I can initiate a query like this.

let circleQuery = geoFirestore.query(withCenter: center, radius: 10)

But not sure what to do after that. How do I get the results from this query?

1 mb limit on documents in Firestore

Hi. From my understanding there is a 1 mb limit on storing documents in Firestore, and according to the Firestore documentation a document should only store 100 fields.
Is it then right to assume that if you wanted to track 1000 or 10 000 for that matter, users with geohashes, that would be impossible with GeoFirestore?

Limit number of results in query?

Since now it's build in firestore, and you can do multiple query parameters, is there a possibility that you can add a feature that allows us to limit the number of matches within the area?

'FirebaseCore/FIRComponentRegistrant.h' file not found

I simply installed the library via pods but the project doesn't compile and throws error in FSTFirestoreComponent.mm. I'm using xcode 10.1 and swift 4.2. The library was updated 7 months ago, is it still in development?

Observer for map region fails when removing observer

First of all thanks for good lib.

I am trying to observe map region, but it fails for second time. Below are steps and source code how I did implement it.

  1. User did click button observe for RegionA.
  2. Works as expected places are placed to the map.
  3. User did move map to RegionB and click button observe.
  4. Before starting observing for new region I am removing observer on the 3rd line. And it hangs on this line forever.

Could you please assist me what I am doing wrong int this implementation.

    private func startForGeoFireObserver() {
        if let queryHandle1 = queryHandle1 {
            geoQuery?.removeObserver(withHandle: queryHandle1)
        }

        let geoFirestoreRef = DBTableName.pr.initQuery()
        let geoFirestore = GeoFirestore(collectionRef: geoFirestoreRef)
        geoQuery = geoFirestore.query(inRegion: mapView.region)
        queryHandle1 = geoQuery?.observe(.documentEntered) { (key, location) in
            print("The document with documentID '\(key)' entered the search area and is at location '\(location)'")
            geoFirestoreRef.document(key!).getDocument(completion: { (document, error) in
                geoFirestoreRef.getDocument(MPR.self, documentId: key!, completion: { (pr, error) in
                    self.add([pr!])
                })
            })
        }
    }

KeyEntered Event Occurs Outside of Query

I am having trouble getting this to work with my project. KeyEntered events get fired when they are not in the query. When debugging the code, I can see that in the updateLocations() function the info.isInQuery is set to false, but the event is still fired? It seems like once a document enters the search criteria (which is already larger than it should be by around half a mile?) it always fires a KeyEntered event, even after query.region is updated. It also occasionally returns two of the same object for key entered events.

I'm not exactly sure what I am doing wrong. Here is where I set up the query:

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let userLocation:CLLocation = locations[0] as CLLocation
        
        self.currentLocation = CLLocation(latitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude)
        
        if self.activeSearchQuery == "Current Location" && self.initialLocationsUpdate == true {
            centerMapOnLocation(location: currentLocation)
            self.regionQuery = GlobalDatabase.geoFirestore.query(inRegion: self.mapView.region)
            let queryHandle = self.regionQuery.observe(.documentEntered, with: { (key, location) in
                print("The document with documentID '\(key)' entered the search area and is at location '\(location)'")
                // Get document here
                }
            })
            self.initialLocationsUpdate = false
        }
    }

Then I update the region when the user moves the map location:
self.regionQuery.region = self.mapView.region
Does anybody know what I am doing incorrectly?

Incorrect Results

I am using GeoFirestore to run geo queries against my Firebase Firestore. It seems to generally work but is returning more results than it should once I test with a radius of more than 25 miles. The closest location in my Firestore is 103 miles from the location I'm testing with. I've tested in 25 mile increments. 25 miles doesn't return any locations, 50 miles returns the closest one, 75 returns the closest one, and 100 miles returns all three of my test locations. Any idea what I'm doing wrong?

func getFacilites() {
        self.facilities = [[String: Any]]()
        
        let currentLatitude = self.currentLocation.coordinate.latitude
        let currentLongitude = self.currentLocation.coordinate.longitude
        
        let geoFireStore = Constants.geoFirestore
        let circleQuery = geoFireStore.query(withCenter: GeoPoint(latitude: currentLatitude, longitude: currentLongitude), radius: milesToKilometers())
        let _ = circleQuery.observeReady {
            print("All initial data has been loaded and events have been fired!")
            if self.facilities?.count == 0 {
                // ----------------------------------------------------------------
                // Alert user that no results were found with their search distance
                // ----------------------------------------------------------------
            }
        }
        let _ = circleQuery.observe(.documentEntered, with: { (key, location) in
            if let key = key {
                Constants.firestore.collection("facilities").document(key).getDocument { (document, error) in
                    if let document = document, document.exists {
                        self.facilities?.append(document.data()!)
                        self.addFaciltiesToMap()
                    } else {
                        print("Document does not exist.")
                    }
                }
            }
        })
    }
func milesToKilometers() -> Double {
        return self.searchDistance * 1.60934
    }

unable to update Firebase due to Geofirestore/Geofire dependencies

I want to update Firebase, so I updated the GeoFirestore podspec dependency to 'Firebase', '> 6.1.0'. However, Geofirestore has a Geofire dependancy which has a Firebase/Database (>5.0) dependency. What can I do to update Firesbase with these dependencies?

[!] CocoaPods could not find compatible versions for pod "Firebase/Database":
  In Podfile:
    Geofirestore (from 'https://[email protected]/CollinEsmon/GeoFirestore-iOS.git') was resolved to 1.0.0, which depends on
      GeoFire (~> 3.0) was resolved to 3.0.0, which depends on
        Firebase/Database (~> 5.0)

Specs satisfying the 'Firebase/Database (~> 5.0)' dependency were found, but they required a higher minimum deployment target.

Update Docs Link

Thanks for the well documented documentation! The link in the readme for the documentation throws a 404 not found.
Thanks πŸ‘

Results in miles?

Hi,
I've done some testings to the results.
I've noticed that when i query for 1 km radius, it gives me results within 1.6 km.
Is it possible that the radius is in miles and not in km?
I know what's written in the docs, but that's the results i get.
does anybody else tested this?

[!] CocoaPods could not find compatible versions for pod "FirebaseCore":

[!] CocoaPods could not find compatible versions for pod "FirebaseCore":
In snapshot (Podfile.lock):
FirebaseCore (= 6.9.1, ~> 6.8)

In Podfile:
Firebase/Firestore was resolved to 6.28.1, which depends on
Firebase/CoreOnly (= 6.28.1) was resolved to 6.28.1, which depends on
FirebaseCore (= 6.9.1)

Firebase/Firestore was resolved to 6.28.1, which depends on
  FirebaseFirestore (~> 1.16.2) was resolved to 1.16.2, which depends on
    FirebaseCore (~> 6.8)

Geofirestore was resolved to 0.1.0, which depends on
  FirebaseCore (~> 5.0.3)

pls help me

Capturing results outside of the search radius

I am using:

geoQuery = geoFirestore.query(withCenter: location, radius: distance)

where 'distance' is taking a value from UI slided. I have checked the coordinates to validate distance between a test user 1 and test user 2 to be 24km roughly. But the other user still appears in the results even when I reduce the radius below 24km. All of the way until I reduce it to 8 km.

It seems like the center point to radius for whatever reason is not being calculated correctly between these points.

Any advice on this?

Where in the GeoFirestore framework is this method defined?

macOS support

I've just started looking into Catalyst support for my app and have hit the problem that Geofirestore isn't compatible with macOS.

Is it possible to add macOS support for the library please?

Simple, and highly useful feature request

Hello, i already use Geofire With Firebase Realtime database on android and i don't know why on android there is the "data event" feature ( https://github.com/imperiumlabs/GeoFirestore-Android#data-events )
and not present on iOS. I really need the data in the whole document not only the Location.

In fact i have many other parameter in the document where i set the geofire location., and when i execute a query to find who is in a certain geoCircle, i still need to check if those "returned results" comply with the other criterias

My question is:
are you planning on adding "data events" support for iOS ? other wise i will have to retrieve all document ID and do a firestore query with every single id to check if those documents comply with the other criterias than location. And according to firstore pricing scheme, u know this way of doing this is a deal breaker.
I am waiting for response.
Keep up the good work

Cheers

Pod Install Dependency Error for Swift

Hi all,

I want to install FirebaseFirestore and FirebaseFirestoreSwift and Geofirestore all.

But this is impossible for now because of the dependencies. I tried every solution but dependency version is too old and FirestoreSwift not supported that for FirebaseFirestore.

Geofirestore (> 1.2) was resolved to 1.2.0, which depends on
FirebaseFirestore (
> 0.12)

Thanks in advance!

Compound query support?

Is it possible do to do compound queries? (e.g. within 10 miles of this location with "attribute" equals something)

GFSQuery .reset() Dead loop

xCode 10.1, Swift 4.2.

There's property 'queries' of type Set in GFSQuery class.
In "reset()" function iterating through elements in for loop when marking element as optional leads to dead lock.
As i can see there's no need to mark them as optional because Set< GFGeoHashQuery> can't contain nil. Simply removing '?' will fix the issue.

BTY. Interesting, this dead lock can be reproduced in playground with just 4 lines:
var queries = Set< String >()
for query: String? in queries {
print(query ?? "")
}

Dependency conflict

When I try to install that library into my project, CocoaPods gives me the following message:

[!] CocoaPods could not find compatible versions for pod "FirebaseFirestore":
In snapshot (Podfile.lock):
FirebaseFirestore (= 1.2.1)

In Podfile:
Firebase/Firestore was resolved to 5.20.2, which depends on
FirebaseFirestore (= 1.2.1)

Geofirestore was resolved to 0.1.0, which depends on
  FirebaseFirestore (~> 0.12.3)

What should I do?

Is there any way to get GeoQueryDataEventListener event like android

I've used geofirestore in android and in android code I can get DocumentSnapshot using GeoQueryDataEventListener listener. https://github.com/imperiumlabs/GeoFirestore-Android#data-events
Is there any way to get same functionality in iOS ?
I want onDocumentEntered,onDocumentExited,onDocumentMoved and onDocumentChanged callback. I've checked Enter, Move, Exit listener of geo query it working fine, but I want document data as well not just document Id. Let me know if possible using any call back
Thanks

How can I bind GeoQueries to UITableView with FirebaseUI?

This is how I currently bind my normal queries to UITableView with FirebaseUI library. Is there any way I can use GeoQueries here?

var dataSource: FUIFirestoreTableViewDataSource!
var query: Query = Firestore.firestore().collection("posts")

dataSource = tableView.bind(toFirestoreQuery: query) { (tableView, indexPath, snapshot) -> UITableViewCell in
            
            //Get Post
            var snapshotData = snapshot.data()!
            snapshotData["documentID"] = snapshot.documentID
            let post = try! FirebaseDecoder().decode(Post.self, from: snapshotData)
            
            return self.cellForRow(tableView: tableView, indexPath: indexPath, post: post)
        }

Query not working if stored as GeoPoint

I'm using GeoFirestore in both Android and iOS. With Android, to set a location the only option is to upload as a GeoPoint e.g. [0ΒΊ N 0ΒΊ E]. It looks like with iOS either a GeoPoint or an array of Double can be uploaded. This causes issues when querying since the iOS client is looking for an array of doubles.

internal func childAdded(_ snapshot: DocumentSnapshot?) {
        let lockQueue = DispatchQueue(label: "self")
        lockQueue.sync {
            
            let l = snapshot?.get("l") as? [Double?]
            if let lat = l?[0], let lon = l?[1], let key = snapshot?.documentID {
                let location = CLLocation(latitude: lat, longitude: lon)
                updateLocationInfo(location, forKey: key)
            }else{
                //TODO: error??
            }
            
        }
    }

This causes all queries to fail.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.