setInfoWindowAdapter不呈现标记信息窗口



这是我的第一个问题,很抱歉出现格式错误或类似问题。

我正试图将信息窗口添加到标记中,这些标记由谷歌实用程序中的ClusterManager集群,但我的项目不能由我的自定义InfoWindowAdapter渲染,这就是我正在尝试做的。

在onMapReady回调之后,我初始化集群管理器,如下所示:

mClusterManager = new ClusterManager<>(this, mMap);
mClusterManager.setRenderer(new ClusterMarkerRenderer(this, mMap, mClusterManager));
mClusterManager.setOnClusterClickListener(cluster -> {
LatLngBounds.Builder builder = LatLngBounds.builder();
for (CarMapItem item : cluster.getItems()) {
builder.include(item.getPosition());
}
final LatLngBounds bounds = builder.build();
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
return true;
});
mMap.setInfoWindowAdapter(new InfoWindowCarAdapter(this));

ClusterMarkerRenderer类(仅重要部分(:

public class ClusterMarkerRenderer extends DefaultClusterRenderer<CarMapItem> {
public ClusterMarkerRenderer(Context context, GoogleMap map, ClusterManager<CarMapItem> clusterManager) {
super(context, map, clusterManager);
}
@Override
protected void onBeforeClusterItemRendered(CarMapItem item, @NotNull MarkerOptions markerOptions) {
if (item.getIcon() != null) {
markerOptions.icon(item.getIcon());
}
if (!item.hasCustomBitmap()) {
markerOptions.rotation(item.getRotation());
}
markerOptions.title(item.getName());
markerOptions.anchor(0.5f, 0.5f);
markerOptions.flat(true);
markerOptions.infoWindowAnchor(0.5f, 0.5f);
markerOptions.snippet(item.getImei() + "#" + item.getPosition().latitude
+ "#" + item.getPosition().longitude + "#" + item.getRotation() + "#" + item.getIconName() + "#" + item.getName());
super.onBeforeClusterItemRendered(item, markerOptions);
}

@Override
protected void onClusterItemRendered(@NotNull CarMapItem item, @NotNull Marker marker) {
super.onClusterItemRendered(item, marker);
marker.setTag(item);
}
}

这是我设置标记选项的地方,在渲染簇项目之前,我的图标已经设置,一切都很好,但在渲染之后,我只将我的项目设置为标签,以检索绘图信息,之后它不会渲染任何内容。还有我的最后一个类,InfoWindowCarAdapter:

public class InfoWindowCarAdapter implements GoogleMap.InfoWindowAdapter {
private View myContentsView;
private Activity context;

@SuppressLint("InflateParams")
public InfoWindowCarAdapter(Activity context) {
this.context = context;
myContentsView = context.getLayoutInflater().inflate(R.layout.item_car_info, null);
}
@Override
public View getInfoContents(Marker marker) {
Log.e(TAG, "GET INFO CONTENTS FROM MARKER");
CarMapItem object = (CarMapItem) marker.getTag();
if (object != null) {
TextView tvTitle = myContentsView.findViewById(R.id.txt_car_name);
if (object.getItemType() == 1) {
((TextView) myContentsView.findViewById(R.id.txt_adit_info)).setText(String.format(Locale.getDefault(), "%s", Helper.getFormatedAlarmWithVars(context, object.getSpeed(),
object.getIconName(), object.getVar2())));
(myContentsView.findViewById(R.id.txt_status)).setVisibility(View.GONE);
(myContentsView.findViewById(R.id.ic_status_icon)).setVisibility(View.GONE);
} else {
TextView title = myContentsView.findViewById(R.id.txt_status);
ImageView icon = myContentsView.findViewById(R.id.ic_status_icon);

((TextView) myContentsView.findViewById(R.id.txt_adit_info)).setText(String.format(Locale.getDefault(), "%s", "Click for more info"));
if (object.getCarEngineStatus() == 1) {
title.setText(String.format(Locale.getDefault(), "%d KM/h", object.getSpeed()));
} else {
title.setText(Helper.formatSecondPrecise(context, object.getLastActivityTime()));
}
icon.setImageResource(Helper.getIconResIdByCarStatus(object.getVehicleStatus()));
(myContentsView.findViewById(R.id.txt_status)).setVisibility(View.VISIBLE);
(myContentsView.findViewById(R.id.ic_status_icon)).setVisibility(View.VISIBLE);
}

tvTitle.setText(object.getName());
return myContentsView;
}
return myContentsView;
}
@Override
public View getInfoWindow(Marker marker) {
return null;
}
}

当这个类被调用时,get-info内容永远不会既不获取信息窗口,即使我试图记录消息,仍然没有来自这个类的输出,只有来自构造函数的输出。

你能帮我吗?

如果有人需要,我自己解决了,错误如下:在我的活动中,我将InfoWindowAdapter设置为谷歌地图对象,我必须将ClusterManager的MarkerManager设置为谷歌映射对象,然后将我的自定义信息窗口适配器设置为集群管理器的标记集合,如下所示:

mMap.setInfoWindowAdapter(mClusterManager.getMarkerManager());
mClusterManager.getMarkerCollection().setInfoWindowAdapter(new InfoWindowCarAdapter(this));

如果有人需要这个,就在这里:(

相关内容

  • 没有找到相关文章

最新更新