问题
The android geofire onKeyEntered is never executed for matching queryLocation. But onGeoQueryReady method is executed.
so when I click on the menu bottombar, the addGeoQueryEventListener is executed and the onGeoQueryReady method is executed. But the onKeyEntered method is never executed. as you can see in the attachment, I have the location in the same node as the top level node. I have also include child path "xxx_location" in the DB reference. below are my API version.
Geofire 2.1.1'
firebase-core:9.0.2'
Code:
///geofire connection
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
DatabaseReference refLowLevel = ref.child("xxxxx_location");
if (refLowLevel!=null) {
GeoFire geoFire = new GeoFire(refLowLevel);
// creates a new query around [37.7832, -122.4056] with a radius of 0.6 kilometers
geoQuery = geoFire.queryAtLocation(new GeoLocation(37.12314,-122.49182),1.80);
Log.i(TAG, "query-------->"+geoQuery);
markers = new HashMap<String, Marker>();
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, GeoLocation location) {
Log.i(TAG, "inside painter onkeynetered-------->");
//Marker marker = map.addMarker(new MarkerOptions().position(new LatLng(location.latitude, location.longitude)));
//markers.put(key, marker);
}
@Override
public void onKeyExited(String key) {
Log.i(TAG, "inside painter onkeyexited-------->");
}
@Override
public void onKeyMoved(String key, GeoLocation location) {
System.out.println(String.format("Key %s moved within the search area to [%f,%f]", key, location.latitude, location.longitude));
}
@Override
public void onGeoQueryReady() {
Log.i(TAG, "inside painter onqueryready-------->");
}
@Override
public void onGeoQueryError(DatabaseError error) {
System.err.println("There was an error with this query: " + error);
}
});
}
回答1:
Your JSON is missing the g
keys, which are the geohashes that Geofire uses to query. Without the g
keys it won't find any keys in any query.
For an example of how to use Geofire to set a location in the database, see the documentation:
geoFire.setLocation("firebase-hq", new GeoLocation(37.7853889, -122.4056973));
If you want to know what setLocation
does, see its code: https://github.com/firebase/geofire-java/blob/8385c3148f816807ea3e1873c5e3772d76856057/src/main/java/com/firebase/geofire/GeoFire.java#L162
来源:https://stackoverflow.com/questions/43823882/android-geofire-onkeyentered-not-trigged