How can I get the all locations that are near to a passed GeoLocation(double lat, double lng)
using Geo Queries.
I have the following code (and it happens nothing):
public void setCurrentLatLng(double lat, double lng){
this.lat = lat;
this.lng = lng;
GeoLocation geoLocation = new GeoLocation(lat, lng);
updateCurrenLocation(geoLocation);
GeoQuery geoQuery = geoFire.queryAtLocation(geoLocation, 8f);
geoQuery.addGeoQueryDataEventListener(new GeoQueryDataEventListener() {
@Override
public void onDataEntered(DataSnapshot dataSnapshot, GeoLocation location) {
Log.d("geoQuery","onDataEntered "+dataSnapshot.toString());
// ...
}
@Override
public void onDataExited(DataSnapshot dataSnapshot) {
Log.d("geoQuery","onDataExited "+dataSnapshot.toString());
// ...
}
@Override
public void onDataMoved(DataSnapshot dataSnapshot, GeoLocation location) {
Log.d("geoQuery","onDataMoved "+dataSnapshot.toString());
// ...
}
@Override
public void onDataChanged(DataSnapshot dataSnapshot, GeoLocation location) {
Log.d("geoQuery","onDataChanged "+dataSnapshot.toString());
// ...
}
@Override
public void onGeoQueryReady() {
// ...
Log.d("geoQuery","onGeoQueryReady");
}
@Override
public void onGeoQueryError(DatabaseError error) {
Log.d("geoQuery","onGeoQueryError");
// ...
}
});
this.setChanged();
notifyObservers();
this.clearChanged();
Log.d("update","clearChanged");
}
I think I'm open to modify the data struct if needed.
Logs
09-12 08:55:33.818 17710-17710/es.rchampa.weirdo D/geoQuery: lat=40.4430883 lng=-3.721805
09-12 08:55:33.982 17710-17710/es.rchampa.weirdo D/geoQuery: lat=40.4430883 lng=-3.721805
09-12 08:55:33.986 17710-17710/es.rchampa.weirdo D/geoQuery: onGeoQueryReady
09-12 08:55:34.025 17710-17710/es.rchampa.weirdo D/geoQuery: onGeoQueryReady
Gradle file
....
// Firebase
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-crash:16.2.0'
implementation 'com.google.firebase:firebase-core:16.0.3'
// Firebase UI
implementation 'com.firebaseui:firebase-ui-database:1.2.0'
//Firebase GeoFire
implementation 'com.firebase:geofire-android:2.3.1'
// Google Play Services
implementation 'com.google.android.gms:play-services-auth:16.0.0'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
....
UPDATE
I can grant access to my private repo if you wish.
error
fromonGeoQueryError()
method? What does it print? – Footpace