imperiumlabs / geofirestore-ios Goto Github PK
View Code? Open in Web Editor NEWGeoFirestore for iOS - Realtime location queries with Firestore
License: MIT License
GeoFirestore for iOS - Realtime location queries with Firestore
License: MIT License
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?
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!
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.
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
The link at the bottom of the readme takes me to a 404: here
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.
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?
Is it possible to get the results for .query(inRegion: region)
randomly? I'm getting the same sequence of results everytime
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?
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?
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?
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.
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!])
})
})
}
}
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?
I would like to upgrade my project to swift 5.0 and update it to the latest firebase SDK (6.9.0 - September 23, 2019). I was wondering when you plan on updating thanks.
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
}
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.
Thanks for the well documented documentation! The link in the readme for the documentation throws a 404 not found.
Thanks π
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":
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
Issue was with Firestore, not your code. Thank you
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?
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?
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
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> 0.12)
FirebaseFirestore (
Thanks in advance!
This seems to be reverted because I don't have the method to limit or access to the limit variable. I also saw that the second commit in #4 seemed to remove the limit functionality
Originally posted by @dbake in https://github.com/imperiumlabs/GeoFirestore-iOS/issue_comments#issuecomment-451709334
Is it possible do to do compound queries? (e.g. within 10 miles of this location with "attribute" equals something)
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 ?? "")
}
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?
Hi,
could you compile it for iOS 13. Thanks?
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
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)
}
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.