【发布时间】:2018-08-24 17:00:21
【问题描述】:
我需要 Firebase 数据库方面的帮助。
我要做的是在我的地图上显示来自 AvailableWorkers 的所有用户(例如,N2GCEIGYBaRiNrFPawklx1NymF3、ruN5PaZC0WNZYm6YJrRtbQVXOoH2)。
这是 Firebase 数据库的屏幕截图
这是我当前的代码:
private void loadAllAvailableWorkers(final LatLng location) {
//Delete markers on the map including client location and available workers
mMap.clear();
//After delete, add location back
mMap.addMarker(new MarkerOptions()
.position(location)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_client_marker))
);
//Load all available Workers
DatabaseReference dbWorkerLocation = FirebaseDatabase.getInstance().getReference(Common.available_workers_table);
GeoFire gfWorkerLocation = new GeoFire(dbWorkerLocation);
GeoQuery gqWorkerLocation = gfWorkerLocation.queryAtLocation(new GeoLocation(location.latitude, location.longitude), distance);
gqWorkerLocation.removeAllListeners();
gqWorkerLocation.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, final GeoLocation location) {
FirebaseDatabase.getInstance().getReference(Common.user_workers_table)
.child(key)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//Add plumber to the map
mMap.addMarker(new MarkerOptions()
.position(new LatLng(location.latitude, location.longitude))
.flat(true)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_worker_marker))
);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
@Override
public void onKeyExited(String key) {
}
@Override
public void onKeyMoved(String key, GeoLocation location) {
}
@Override
public void onGeoQueryReady() {
//Distance will search within 3km
if(distance <= LIMIT) {
distance++;
loadAllAvailableWorkers(location);
}
}
@Override
public void onGeoQueryError(DatabaseError error) {
}
});
}
任何帮助将不胜感激。先感谢您! :)
已编辑
DatabaseReference dbWorkerLocation = FirebaseDatabase.getInstance().getReference(Common.available_workers_table);
这是我需要(再次)获取子当前用户 ID 的父级的部分
【问题讨论】:
-
您想显示这些 id:
N2GCEIGYBaRiNrFPawklx1NymF3和ruN5PaZC0WNZYm6YJrRtbQVXOoH2? -
太好了,你还活着!是的,我希望它们显示在地图上,但在获取子孩子(如管道工等)时似乎遇到了麻烦。
-
你想查询什么ids或者names?用更详细的图片更改该图片。
-
嗨,亚历克斯!请查看有关该问题的更新。我尝试了您对 stackoverflow.com/a/49298413/9419938 所做的操作,但我似乎无法在我的地图上显示标记。
-
换一张更详细的图片。展开
N2GCEIGYBaRiNrFPawklx1NymF3和ruN5PaZC0WNZYm6YJrRtbQVXOoH2节点以清楚地看到。
标签: android google-maps firebase firebase-realtime-database