gpt4 book ai didi

android - google map marker clustering ad custom Infowindow Adapter 如何为 clusterItem(标记)设置标签

转载 作者:太空狗 更新时间:2023-10-29 13:50:23 25 4
gpt4 key购买 nike

我遇到了一个问题...我正在尝试使用 google maps api 在 android 上制作带有标记的 map ,并且我还设法使用 clusterManager 将它们聚类,到目前为止一切正常,但问题是当我尝试制作 < strong>custom Infowindow 用于 pin,我可以获得标记的标题、 fragment 和位置,但其他信息(如标记标签、id 等)似乎是不可能的。
我认为问题是 ClusterItem 它只覆盖了标题、 fragment 和位置。有人可以帮我解决这个问题吗? 这是我的代码: 这是我从 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 类:

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: “getInfoContents(Marker marker)”类似于:“getInfoContents(MyMission marker)”......

最佳答案

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

关于android - google map marker clustering ad custom Infowindow Adapter 如何为 clusterItem(标记)设置标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48650333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com