0

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);
          }
      });

  }

enter image description here

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
user1439582
  • 103
  • 2
  • 14
  • If you get no keys before `onGeoQueryReady` gets called, that means that there are no keys matching your query. – Frank van Puffelen May 06 '17 at 18:22
  • Thank you. As you can see in the screen shot, I have three Nodes with name as IDs wuch as 123 with three different locations and these IDs are inside parallel node below still onkeyentered not executed. I been trying for many weeks and no luck – user1439582 May 06 '17 at 18:49
  • 1
    Yeah, that does not look like a location that was written with Geofire. You're missing `g` keys, which are the geohases that Geofire uses to query. – Frank van Puffelen May 06 '17 at 18:59
  • Or is it not connecting to firebase DB. Can I just change the distance from 1.80km to 0.0 and try – user1439582 May 06 '17 at 18:59
  • Actually these above JSON is handcrafted.so no g keys is g key important to read if so can I enter some nod g in xxxx-location with dummy value.and try will it work – user1439582 May 06 '17 at 19:00
  • Hand-crafting the JSON for Geofire seems like a waste of time. Just use the methods provided for it: https://github.com/firebase/geofire-java#setting-location-data. If you want to know what it does: https://github.com/firebase/geofire-java/blob/8385c3148f816807ea3e1873c5e3772d76856057/src/main/java/com/firebase/geofire/GeoFire.java#L162 – Frank van Puffelen May 06 '17 at 22:05

1 Answers1

2

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

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807