所以对于这点我即将面临2个问题, 第一个是
运行应用程序时使用未指定的索引。考虑添加'“。indexOn”:“g”'at Geofire为您的安全和Firebase数据库规则提供更好的帮助 性能
这些是我通过firebase的安全规则
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
第二个问题,我试图获得我的半径以外的用户数量,除了我,由于某种原因,我发现只有一个事件,数据库上的位置是2,半径是100km,这里是代码示例,请帮帮我
final Set<String> runnersNearby = new HashSet<String>();
geoFire.setLocation(uid, new GeoLocation(lat, lang));
GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(lat, lang), radius);
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, GeoLocation location) {
Toast.makeText(UserProfile.this, "Successfully Found", Toast.LENGTH_SHORT).show();
if (key != user.getUid())
runnersNearby.add(key);
Log.d("Number of users", String.valueOf(runnersNearby.size()));
Log.d("KEY", String.valueOf(key));
}
@Override
public void onKeyExited(String key) {
Toast.makeText(UserProfile.this, "left the place", Toast.LENGTH_SHORT).show();
runnersNearby.remove(key);
}
@Override
public void onKeyMoved(String key, GeoLocation location) {
Toast.makeText(UserProfile.this, "key moved but here", Toast.LENGTH_SHORT).show();
}
@Override
public void onGeoQueryReady() {
System.out.println("All initial data has been loaded and events have been fired!");
}
@Override
public void onGeoQueryError(DatabaseError error) {
Toast.makeText(UserProfile.this, "Error Occured", Toast.LENGTH_SHORT).show();
}
});
答案 0 :(得分:1)
该消息非常明确:
{
"rules": {
".read": "auth != null",
".write": "auth != null",
"Geofire": {
".indexOn": "g"
}
}
}
答案 1 :(得分:0)
1-保存位置到firebase:geoFire.setlocation ......
来自firebase的2个查询位置:getlocationforkey .....
a-按区域geoFire.querybyregion(区域)查询你需要在mapKit中用坐标声明区域。
b-观察事件:
1- ObserveEventType(.keyEntered ....)
2- .................(。keyExited ....)