Closed razbakov closed 5 years ago
I'm assuming you're testing version 3 of the library. With that in mind I don't believe your import syntax for for firebase is correct. Also you need to instantiate a firestore object, which I don't see.
I see some similarities in what you have to the sample I have in the readme, please give it another look though https://github.com/geofirestore/geofirestore-js/blob/v3.0.0/README.md#documentation
And if you have any questions let me know. I'll keep the issue open till Sunday so you can let me know if that works.
I updated the code, basically I have the part of the code of initialising app and firestore in a separate file.
@razbakov what version are you using? (And would you possibly be cool with making sample of on something like https://codepen.io/ ??)
My versions are:
"firebase": "^5.6.0",
"geofirestore": "^2.2.3",
Here is example - https://codesandbox.io/s/y04wj6zpoj
Ok! This I can easily address. I think you may have been referencing the documentation for version 3 which is located on geofirestore.com, however you're using version 2.x.x
Check out the docs for version 2
And as an example on how to do what you wanted to do...
import * as firebase from 'firebase/app';
import 'firebase/firestore';
import { GeoFirestore } from 'geofirestore'
// Initialize the Firebase SDK
firebase.initializeApp({
// ...
});
// Array to store events
let events = [];
// Create a Firestore collection reference
const collection = firebase.firestore().collection('events');
// Create a GeoFirestore reference
const geofirestore = new GeoFirestore(collection);
// Create a GeoQuery based on a location
const query = geofirestore.query({ center: new firebase.firestore.GeoPoint(48.1077212, 11.6019103), radius: 50 })
// Listener for docs as they come in
query.on('key_entered', ($key, result) => {
result.$key = $key;
events.push(result);
});
// Listener for docs as they exit
query.on('key_exited', ($key) => {
events = events.filter((event) => event.$key !== $key));
});
IF however you want to use version 3.0.0 (as your current code shows), you can install it like this:
npm i geofirestore/geofirestore-js#v3.0.0
It's still in kind of a beta state, however it's almost good to go, and I feel comfortable saying you could/should try it. I'm just writing tests to validate it works, otherwise the development is pretty much done (unless a test tells me I screwed up)
Versions
Code
Console error
Example
https://codesandbox.io/s/y04wj6zpoj