title: Retrieving data using GeoQuery
body: <p>So, I used this library called GeoFire (src: <a href="https://github.com/firebase/geofire-java" rel="nofollow noreferrer">https://github.com/firebase/geofire-java</a>) to get a post from user within a certain distance. In my code, I made a method like this:</p>
  
  <pre><code>private HashMap&lt;String, GeoLocation&gt; getPostAroundUser(DatabaseReference rootRef) {
      final HashMap&lt;String, GeoLocation&gt; postHashMapLocation = new HashMap&lt;String, GeoLocation&gt;();
      DatabaseReference refPostGeo = rootRef.child("geo").child("posts");
      final GeoFire geoFire = new GeoFire(refPostGeo);
      GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(mLatitude, mLongitude), 3);
      geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
          @Override
          public void onKeyEntered(String key, GeoLocation location) {
              Log.i(TAG, "Post with key: " + key + " was added to hash with location (lat, long): (" + location.latitude + ", " + location.longitude + ")");
              postHashMapLocation.put(key, location);
              Log.i(TAG, "number of entry after added " + postHashMapLocation.size());
          }
  
          @Override
          public void onKeyExited(String key) {
              Log.i(TAG, "Post with key: " + key + " was removed");
              postHashMapLocation.remove(key);
          }
  
          @Override
          public void onKeyMoved(String key, GeoLocation location) {
  
          }
  
          @Override
          public void onGeoQueryReady() {
              Log.i(TAG, "number of entry onGeoQueryReady " + postHashMapLocation.size());
          }
  
          @Override
          public void onGeoQueryError(DatabaseError error) {
  
          }
      });
      Log.i(TAG, "total entry in function: " + postHashMapLocation.size()); //postHashMapLocation.size() returns 0
      return postHashMapLocation;
  }
  </code></pre>
  
  <p>But this method returns an empty <code>HashMap</code>, so I added some log to see what is going on, here is the log:</p>
  
  <pre><code>02-21 18:09:32.609 15115-15115/com.example.company.app I/ExampleActivity: total entry in function: 0
  02-21 18:09:32.839 15115-15115/com.example.company.app I/ExampleActivity: Post with key: -Kd7DPzEZHSdGHqfbmna was added to hash with location (lat, long): (-6.1459048, 106.692038)
  02-21 18:09:32.839 15115-15115/com.example.company.app I/ExampleActivity: number of entry after added 1
  02-21 18:09:32.839 15115-15115/com.example.company.app I/ExampleActivity: Post with key: -Kd7DULwW01S9-haorm9 was added to hash with location (lat, long): (-6.1459048, 106.692038)
  02-21 18:09:32.839 15115-15115/com.example.company.app I/ExampleActivity: number of entry after added 2
  02-21 18:09:32.839 15115-15115/com.example.company.app I/ExampleActivity: Post with key: -Kd7Dt6uvs50qddJHxiA was added to hash with location (lat, long): (-6.1459048, 106.692038)
  02-21 18:09:32.839 15115-15115/com.example.company.app I/ExampleActivity: number of entry after added 3
  02-21 18:09:32.839 15115-15115/com.example.company.app I/ExampleActivity: Post with key: -Kd7EOF41MijwSfrxpX1 was added to hash with location (lat, long): (-6.1459048, 106.692038)
  02-21 18:09:32.839 15115-15115/com.example.company.app I/ExampleActivity: number of entry after added 4
  02-21 18:09:32.849 15115-15115/com.example.company.app I/ExampleActivity: Post with key: -KdB3mJvB0K6nSCtNnoL was added to hash with location (lat, long): (-6.1333898, 106.6861029)
  02-21 18:09:32.849 15115-15115/com.example.company.app I/ExampleActivity: number of entry after added 5
  02-21 18:09:32.849 15115-15115/com.example.company.app I/ExampleActivity: Post with key: -KdB3r13H7y3jiovlLdi was added to hash with location (lat, long): (-6.1333898, 106.6861029)
  02-21 18:09:32.849 15115-15115/com.example.company.app I/ExampleActivity: number of entry after added 6
  02-21 18:09:32.849 15115-15115/com.example.company.app I/ExampleActivity: Post with key: -KdB58ArIOFKHrfEnYpr was added to hash with location (lat, long): (-6.1335054, 106.6910521)
  02-21 18:09:32.849 15115-15115/com.example.company.app I/ExampleActivity: number of entry after added 7
  02-21 18:09:32.869 15115-15115/com.example.company.app I/ExampleActivity: number of entry onGeoQueryReady 7
  </code></pre>
  
  <p>It turns out the log I put before returning the <code>HashMap</code> fired up before the log inside the <code>geoQuery</code>. That's why the method return an empty <code>HashMap</code></p>
  
  <p>So, my question is, how do I get the <code>HashMap</code> from inside the <code>onKeyEntered</code> to be returned by this method? Because as you can see from the log, the <code>HashMap</code> was updated inside <code>onKeyPressed</code> but I can't retrieve it to the outside of <code>geoQuery</code>.</p>
  
  <p>Note: I found a similar problem here <a href="https://stackoverflow.com/questions/35821951/error-performing-functions-inside-a-geofire-and-firebase-query">Error performing functions inside a GeoFire and Firebase query</a>, but there is no answer.</p>