2017-02-10 12 views
0

GeofireとFirebaseを使用することで、近くにいるユーザーを取得する機能が実装されましたが、すぐ近くのユーザーのマーカーが表示されます情報ウィンドウを使用して表示するユーザー情報。情報ウィンドウにfirebaseデータベースからJSONデータを取得するにはどうすればよいですか。情報ウィンドウを試してみましたが、結果は得られましたが、自分の情報しか表示されませんでしたここでは、クライアントではないdatabase.Hereコードマーカー情報ウィンドウでユーザーデータを取得firebaseデータベースからアンドロイドのGoogleマップ

ある
@Override 
public void onMapReady(GoogleMap googleMap) { 
    mMap = googleMap; 
    mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); 
    if (mMap != null){ 
     mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() { 
      One one; 
      @Override 
      public View getInfoWindow(Marker marker) { 
       return null; 
      } 

      @Override 
      public View getInfoContents(Marker marker) { 
       View view = getLayoutInflater().inflate(R.layout.user_infowindow,null); 

       TextView nameInfo = (TextView) view.findViewById(R.id.usernameinfowindow); 
       TextView fromInfo = (TextView) view.findViewById(R.id.filltextfrominfowindow); 
       TextView toInfo = (TextView) view.findViewById(R.id.filltexttoinfowindow); 
       CircleImageView profileInfo = (CircleImageView) view.findViewById(R.id.infowindowprofilepic); 

       nameInfo.setText(user_name.getText()); 
       fromInfo.setText(eetsource.getText()); 
       toInfo.setText(eetdestination.getText()); 
       return view; 
      } 
     }); 
    } 

は、これは私の情報ウィンドウのレイアウトである私のデータベース firebase database &ある

<de.hdodenhof.circleimageview.CircleImageView 
     android:id="@+id/infowindowprofilepic" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignParentEnd="true" 
     android:layout_gravity="top|end" 
     app:border_color="@color/white" 
     android:layout_alignParentRight="true" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_alignTop="@+id/infowindowprofilepic" 
     android:layout_toLeftOf="@+id/infowindowprofilepic" 
     android:layout_toStartOf="@+id/infowindowprofilepic"> 

     <TextView 
      android:id="@+id/usernameinfowindow" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top|start" 
      android:text="@string/user_name_corider" 
      android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> 

     <TextView 
      android:id="@+id/textfrominfowindow" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="@dimen/five_dp_padding" 
      android:text="@string/from_corider" 
      android:textColor="@color/black" /> 

     <TextView 
      android:id="@+id/filltextfrominfowindow" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:maxLines="1" 
      android:text="@string/your_starting_point" 
      android:textSize="12sp" /> 

     <TextView 
      android:id="@+id/texttoinfowindow" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/to_corider" 
      android:textColor="@color/black" /> 

     <TextView 
      android:id="@+id/filltexttoinfowindow" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:maxLines="1" 
      android:text="@string/your_destination" 
      android:textSize="12sp" /> 

    </LinearLayout> 

リサイクルビュー

public class One extends LocationData { 

public String name; 
public String from; 
public String to; 
public String when; 
public CircleImageView picture; 

public One(){ 
    // Default constructor required for calls to DataSnapshot.getValue(One.class) 

} 

public One(String name, String from, String to, String when, CircleImageView picture) { 
    this.name = name; 
    this.from = from; 
    this.to = to; 
    this.when = when; 
    this.picture = picture; 

} 

@Exclude 
public Map<String, Object> toMap() { 
    HashMap<String, Object> result = new HashMap<>(); 
    result.put("name", name); 
    result.put("from", from); 
    result.put("to", to); 
    result.put("when", when); 
    result.put("picture", picture); 
    return result; 
} 

@Override 
public void setName(String name) { 
    this.name = name; 
} 

@Override 
public String getName() { 
    return name; 
} 

@Override 
public void setFrom(String from) { 
    this.from = from; 
} 

@Override 
public String getFrom() { 
    return from; 
} 

@Override 
public void setTo(String to) { 
    this.to = to; 
} 

@Override 
public String getTo() { 
    return to; 
} 

@Override 
public void setWhen(String when) { 
    this.when = when; 
} 

@Override 
public String getWhen() { 
    return when; 
} 

}

答えて

0

あなたがgetInfoWindow "ヌル" 返すように設定されているデータベースから詳細情報を取得する際に私を助けたPOJOクラス。それは表示するためのビューを取得していない。追加する必要があります

View view = getLayoutInflater()。inflate(R.layout.user_infowindow、null);

インフォインウインドウを取得し、ビューに戻るように設定します。

リターンビュー;

よろしくお願いします。 -cd

関連する問題