google map marker clustering ad custom Infowindow Adapter 如何为clusterItem(marker)设置tag

google map marker clustering ad custom Infowindow Adapter how to set tag for clusterItem (marker)

我遇到了一个问题... 我正在尝试使用 google 地图 api 在 android 上制作带有标记的地图,并且我还设法使用 clusterManager 对它们进行聚类,一切到目前为止效果很好,但问题是当我尝试为图钉制作 自定义信息窗口 时,我可以获得标记的标题、片段和位置,但其他信息(如标记标签, id 等)这似乎是不可能的。
我认为问题是 ClusterItem 它只覆盖了标题、片段和位置。 有人可以帮我解决这个问题吗? 这是我的代码: 这是我从 firebase:

获取标记的地方
FirebaseDatabase database = FirebaseDatabase.getInstance();
    places = database.getReference("Places");

    places.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            map.clear();
            mClusterManager.clearItems();
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                Double latitude = (Double) postSnapshot.child("Lat").getValue();
                Double longitude = (Double) postSnapshot.child("Long").getValue();
                String name = postSnapshot.getKey();
                String score = postSnapshot.child("score").getValue().toString();
                String photoUrl = postSnapshot.child("photoUrl").getValue().toString();
                String description = postSnapshot.child("description").getValue().toString();
                MyMission mMission = new MyMission(latitude,longitude,name,score);

                mClusterManager.addItem(mMission);

                mClusterManager.cluster();
            }

        }

        @Override
        public void onCancelled(DatabaseError error) {

        }
    });

这里是 clusterItem class:

public class MyMission implements ClusterItem {

private LatLng mPosition;
private String mTitle;
private String mSnippet;

public MyMission(double lat, double lng) {
    mPosition = new LatLng(lat, lng);
}

public MyMission(double lat, double lng, String title, String snippet) {
    mPosition = new LatLng(lat, lng);
    mTitle = title;mSnippet = snippet;

}


@Override
public LatLng getPosition() {
    return mPosition;
}

@Override
public String getTitle() {
    return mTitle;
}

@Override
public String getSnippet() {
    return mSnippet;
}  
}

这是 InfoWindowAdapter:

  public class CustomMarkerInfoWindow implements GoogleMap.InfoWindowAdapter {
private Activity context;

public CustomMarkerInfoWindow(Activity context) {
    this.context = context;
}

@Override
public View getInfoWindow(Marker marker) {
    return null;
}

@Override
public View getInfoContents(Marker marker) {
    View view = context.getLayoutInflater().inflate(R.layout.custom_marker_info_window, null);
    TextView title = view.findViewById(R.id.TitleTextView);
    TextView distance = view.findViewById(R.id.distanceValueTextView);
    TextView points = view.findViewById(R.id.pointsValueTextView);

    title.setText(marker.getTitle());
    distance.setText("2101");
    points.setText(marker.getSnippet());





    return view;
}

如果可以在“InfowindowAdapter: the "getInfoContents(Marker marker)" 类似于:"getInfoContents(MyMission marker)".....

我认为本关于集群管理器的教程可能会对您有所帮助,因为它在标记点击时创建了一个自定义弹出窗口,我认为这正是您所追求的。 Work with ClusterManager