2016-06-14 8 views
2

だから私は繰り返し処理はこのように見ているfirebase構造トラフ関数を作成したい:AndroidのFirebase構造のトラフを反復するには?

{ 
    "users" : { 
    "7e122736-2dd4-4770-a360-a0e7cbe41a43" : { 
    "currentLatitude" : 46.6598714, 
    "currentLongitude" : 23.5637339, 
    "displayName" : "gjsj2", 
    "email" : "[email protected]", 
    "password" : "123" 
}, 
"a09e7e1d-ad3a-4d21-b0ba-069e0999bb93" : { 
    "currentLatitude" : 47.6599014, 
    "currentLongitude" : 23.5636797, 
    "displayName" : "gjsj", 
    "email" : "[email protected]", 
    "password" : "123" 
}, 
"abc29286-fd6d-4088-95da-759828b5835d" : { 
    "currentLatitude" : 50.6599043, 
    "currentLongitude" : 23525.5637188, 
    "displayName" : "gjsj3", 
    "email" : "[email protected]", 
    "password" : "123" 
} 
} 
} 

私はすべての固有のユーザーIDの子を取り、Googleでマーカーを作成するために、彼の座標を使用する関数を作成したいですマップマップ。ここで私は、これまでに得たものだが、それが動作しているように見えるdoesntの:

public void onChildChanged(DataSnapshot snapshot, String s) { 
         for (DataSnapshot userSnapshot : snapshot.getChildren()) { 
          for (DataSnapshot uniqueUserSnapshot : userSnapshot.getChildren()) { 
           Users currentUser = uniqueUserSnapshot.getValue(Users.class); 

           MarkerOptions options = new MarkerOptions() 
             .title(currentUser.getEmail()) 
             .icon(BitmapDescriptorFactory.defaultMarker(getRandomNumberInRange(0, 360))) 
             .position(new LatLng(currentUser.getCurrentLatitude(), currentUser.getCurrentLongitude())); 
           mMap.addMarker(options); 
           Toast.makeText(MainActivity.this, "fsafasfasfas", Toast.LENGTH_SHORT).show(); 
          } 
         } 

       } 

そしてここでは、私のユーザーPOJOです:

package com.licenta.vladut.mmap; 
public class Users { 
String email; 
String displayName; 
String password; 
double currentLatitude; 
double currentLongitude; 


public Users() { 
} 

public Users(String email, String displayName, String password, double currentLongitude, double currentLatitude) { 
    this.email = email; 
    this.displayName = displayName; 
    this.password = password; 
    this.currentLongitude = currentLongitude; 
    this.currentLatitude = currentLatitude; 
} 
public Users(String email, String displayName, String password) { 
    this.email = email; 
    this.displayName = displayName; 
    this.password = password; 

} 

public String getDisplayName() { 
    return displayName; 
} 

public String getEmail() { 
    return email; 
} 

public String getPassword() { 
    return password; 
} 
public double getCurrentLongitude() { 
    return currentLongitude; 
} 

public double getCurrentLatitude() { 
    return currentLatitude; 
} 

}

ことはあなたのアイデアを得るのが大好きです。ありがとうございました。

+0

"しかし、それは動作していないようです" - これは何を意味するのですか? –

+0

それはすべてのユーザーのためのマーカーを作成しません。 –

+0

これは別の問題かもしれません。すべての反復で 'options'オブジェクトをデバッグし、その問題が反復であり、他のものではないことを確認してください。 –

答えて

4

私が質問を正しく理解していれば、あなたは実際にあなたがしたいことに近いです。データベースの子ユーザーを参照してから、ValueEventListenerを追加します。ValueEventListenerは、子ではなく、呼び出されるノードを返します。

+0

ありがとう、それは働いた! –

関連する問題