从firebase数据库获取标记信息窗口android google maps中的用户数据

时间:2017-02-10 15:49:53

标签: android google-maps firebase google-maps-markers geofire

通过使用Geofire和Firebase我已经实现了该功能以获取附近的用户,但是现在它只显示附近用户的标记,我还希望使用信息窗口显示用户信息。所以如何使信息窗口从firebase数据库中获取JSON数据。通过试验信息窗口,我得到了结果,但它只显示了我自己的信息,这是来自客户端而不是数据库。这是代码

  @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>

在回收站视图中从数据库中获取详细信息时帮助我的pojo类

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 个答案:

没有答案