问题描述
从未为匹配的queryLocation执行android geofire onKeyEntered.但是会执行onGeoQueryReady方法.
The android geofire onKeyEntered is never executed for matching queryLocation. But onGeoQueryReady method is executed.
因此,当我单击菜单底栏时,将执行addGeoQueryEventListener并执行onGeoQueryReady方法.但是永远不会执行onKeyEntered方法.正如您在附件中看到的那样,我的位置与顶级节点在同一节点中.我还在数据库参考中包含了子路径"xxx_location".下面是我的API版本.
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'
代码:
///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);
}
});
}
推荐答案
您的JSON缺少g
键,这是Geofire用于查询的geohash.没有g
键,它将不会在任何查询中找到任何键.
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.
有关如何使用Geofire在数据库中设置位置的示例,请参见文档:
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));
如果您想知道setLocation
的功能,请参见其代码: https://github.com/firebase/geofire-java/blob/8385c3148f816807ea3e1873c5e3772d76856057/src/main/java/com/firebase/geofire/GeoFire.java# L162
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
这篇关于Android GeoFire onKeyEntered未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!