我已将坐标保存在火力基地实时数据库中?如何在安卓中检索坐标



因为我已将所有经过身份验证的用户的坐标保存在Firebase实时数据库中。现在我想检索Firebase数据库上的所有坐标以在地图上显示 喜欢单个地图上的多个标记

这是我将位置发送到火力基地的代码

public void onLocationChanged(Location location) {
FirebaseUser user = fb.getCurrentUser();
databaseReference.child("Location").child(user.getUid()).child("parth1234").setValue(location.getLatitude() + " , " + location.getLongitude());
}

现在如何将这些位置检索到地图活动中 因为已经创建了地图活动,但我不知道与此相关的任何内容 请帮助一些代码

提前致谢

我是安卓工作室的初学者

我使用的将位置保存到Firebase方法是正确的方法吗?

您设置正确。
若要检索数据,需要附加值侦听器(有关详细信息 https://firebase.google.com/docs/database/android/read-and-write
执行以下操作:

FirebaseDatabase.getInstance().getReference("Location").child((user.getUid()).child("parth1234").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//Now you can do whatever you want with that location value
//dataSnapshot.getValue(String.class)
//I printed it in the code below for you
System.out.println(dataSnapshot.getValue(String.class));
}
@Override
public void onCancelled(DatabaseError databaseError) {
//Handle the error
}
});

最新更新