mbramwell1 / GeoFire-Android

Query Firestore documents using GeoLocation coordinates.
Apache License 2.0
21 stars 0 forks source link

how setlocation? #13

Open zoro238 opened 5 years ago

zoro238 commented 5 years ago

How do I put my data in it (set loaction ? and view error

     FirebaseFirestore db = FirebaseFirestore.getInstance();
     CollectionReference myCollection2 = db.collection("xxxx");
     GeoFire geoFire = new GeoFire(myCollection2);

this CollectionReference is database ref

mbramwell1 commented 5 years ago

Hey,

So basically geofire doesnt have save capability, thats provided by firebase itself. What you'll need to do (for now at least) is save the document as normal, and in the oncomplete use:

geoFire.setLocation(YOUR_ID, YOUR_LATITUDE, YOUR_LONGITUDE, this);

You'll need the class youre calling setLocation from to implement SetLocationListener. In the onCompleted method you'll either get null if the location was set successfully, or an exception if not.

zoro238 commented 5 years ago

ok i am test then replay

zoro238 commented 5 years ago

this error

![Uploading 12.JPG…]()

zoro238 commented 5 years ago

12

mbramwell1 commented 5 years ago

Hi,

Please check the docs. You need to give GeoFire your collection reference rather than your database

private CollectionReference myCollection = db.collection("myCollection"); private GeoFire geoFire = new GeoFire(myCollection);

zoro238 commented 5 years ago

now ok , but record one value where lat,lon 113 g

zoro238 commented 5 years ago

113

zoro238 commented 5 years ago
    FirebaseFirestore db = FirebaseFirestore.getInstance();
    CollectionReference myCollection = db.collection("myCollection");
    GeoFire geoFire= new GeoFire(myCollection);
    geoFire.setLocation("hi", mlocation.getLatitude(), mlocation.getLongitude(),this);
zoro238 commented 5 years ago
    FirebaseFirestore db = FirebaseFirestore.getInstance();
    CollectionReference myCollection = db.collection("myCollection");
    GeoFire geoFire= new GeoFire(myCollection);
    geoFire.setLocation("hi", mlocation.getLatitude(), mlocation.getLongitude(),this);
mbramwell1 commented 5 years ago

Hi,

I've just updated the docs in the readme. Please check those. You'll need to use standard Firestore utilities to store your document first. GeoFire only updates the geoFireLocation field. The google docs are good for explaining how to use Firestore to store documents.

https://firebase.google.com/docs/firestore/quickstart

You'll need to store your document, and then in the onComplete, use geoFire.setLocation() to update the document with the id reference you get back and the latitude and longitude values.

mbramwell1 commented 5 years ago

I'm going to close this issue, as I believe you should now have all the information you need.

To summarise:

In your examples, geoFire.setLocation needs to go in the onSuccess listener for your user addition. In there, use the ID from the returned document reference, and your latitude and longitude from the user object. Then you will have your latitude and longitude, and the necessary geoFireLocation.

zoro238 commented 5 years ago

Inside the method appears a line but outside without a line ..

1010

mbramwell1 commented 5 years ago

Hi. You are not implementing the listener. As the message tells you, you need to implement SetLocationListener.

Thanks, Martin

zoro238 commented 5 years ago

How to implement SetLocationListener.

zoro238 commented 5 years ago

i implement public class Find extends AppCompatActivity implements MyTracker.ADLocationListener , SetLocationListener {

and add

@Override
public void onCompleted(Exception exception) {
    Log.w(TAG, "onCompleted ", exception);
}

and same error >>

mbramwell1 commented 5 years ago

Okay, let me have a look. If you've implemented everything correctly then it seems there could be an issue. Leave it with me and I'll have a look ASAP.

zoro238 commented 5 years ago

ok and thank you alots