从Firebase获取地图标记[关闭]

问题描述 投票:0回答:1

我需要获取数据库的坐标,并使用这些坐标将标记放置在确切的位置。

我的数据库:

我的代码:

private GoogleMap mMap;
DatabaseReference f_database = FirebaseDatabase.getInstance().getReference().child("users");

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps_user);

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}



@Override
public void onMapReady(GoogleMap googleMap) {

    mMap = googleMap;
    f_database.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot child : dataSnapshot.child("profile").getChildren()) {
                String rightLocation = child.child("lat").getValue().toString();
                String leftLocation = child.child("lng").getValue().toString();

                double location_left = Double.parseDouble(leftLocation);
                double location_right = Double.parseDouble(rightLocation);
                LatLng cod = new LatLng(location_left, location_right);
                googleMap.addMarker(new MarkerOptions().position(cod).title("pedik"));
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

}}
android google-maps firebase firebase-realtime-database
1个回答
0
投票

编辑回答

for (DataSnapshot child : dataSnapshot.getChildren()){ 
   String lat = child.child("profile").child("lat").getValue().toString();
}
© www.soinside.com 2019 - 2024. All rights reserved.