gpt4 book ai didi

Android Maps ClusteredMarkers - 不显示未聚类?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:01:34 27 4
gpt4 key购买 nike

我正在使用来自 here 的 Google Maps Android 标记聚类实用程序我从服务器收到的列表中添加了一堆项目(大约 700 个)。我已经解决了我最初的错误,我可以看到集群,然后放大它们并看到它们分解成单独的标记。然而,有几个项目与其他项目相距很远,因此即使在最大程度缩小时,它们也永远不会聚集在一起。出于某种原因,这些项目没有显示在我的 map 上 - 放大时不显示,缩小时不显示。

我已经检查了坐标,它们是真实的,并且在我开始使用聚类之前我可以看到这些项目没有问题,所以我假设我在我的聚类代码中做错了什么。

这是一些代码:

private void setUpClusterer() {
// Initialize the manager with the context and the map
mClusterManager = new ClusterManager<>(getActivity(), map);
vendorRenderer = new VendorRenderer();
mClusterManager.setRenderer(vendorRenderer);
mClusterManager.setOnClusterClickListener(this);
mClusterManager.setOnClusterItemClickListener(this);
//point the maps listeners at the listeners implemented by the cluster manager
map.setOnCameraChangeListener(mClusterManager);
map.setOnMarkerClickListener(mClusterManager);

//add items to the cluster manager
addClusterItems(-1);
mClusterManager.cluster();
}

private void addClusterItems(int positionToMark) {
if (null == list) {
return;
}
LatLng position;
int maxMarkers = Math.min(list.size(), getResources().getInteger(R.integer.number_of_results_on_map));

mClusterManager.clearItems();

for (int i = 0; i < maxMarkers; i++) {

vendorItem = list.get(i);

if (vendorItem.getAddress().contains("Remote 1")) {
Log.e("Kibi", "Adding Remote 1, pos = " + i);
Log.e("Kibi", "Coordinates =" + vendorItem.getPointCoordinates().toString());
}
if (vendorItem.getAddress().contains("Clustered 1")) {
Log.e("Kibi", "Adding Clustered 1, pos = " + i);
Log.e("Kibi", "Coordinates =" + vendorItem.getPointCoordinates().toString());
}
if (vendorItem.getAddress().contains("Remote 2")) {
Log.e("Kibi", "Adding Remote 2, pos = " + i);
Log.e("Kibi", "Coordinates =" + vendorItem.getPointCoordinates().toString());
}
VendorMapItem item = new VendorMapItem(vendorItem.getPointCoordinates(),
"Some other text");
if (i == positionToMark) {
selectedItem = item;
}

mClusterManager.addItem(item);
}
if (-1 == positionToMark) {
selectedItem = null;
}
}

这显示了添加的项目 - 我添加的日志帮助我看到我的 2 个远程项目添加了良好的坐标,并且看起来与我选择的集群项目(可见)相似(虽然距离很远)

这是渲染器代码:

/* This draws the markers for us */
private class VendorRenderer extends DefaultClusterRenderer<VendorMapItem> {
Context context = getActivity().getApplicationContext();
public final IconGenerator mIconGenerator = new IconGenerator(context);
public final IconGenerator mSelectedIconGenerator = new IconGenerator(context);
private final View mItemView;
private final View mSelectedItemView;

public VendorRenderer() {
super(getActivity().getApplicationContext(), map, mClusterManager);

// Create selected custom Marker
RelativeLayout selectedContainer = (RelativeLayout) view.findViewById(R.id.marker_map_selected_container);
mSelectedItemView = ((LayoutInflater) getActivity().getSystemService
(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.map_marker_selected_layout, selectedContainer, false);
mSelectedIconGenerator.setContentView(mSelectedItemView);
mSelectedIconGenerator.setBackground(null);

// Create custom Marker
LinearLayout container = (LinearLayout) view.findViewById(R.id.text_marker_map_container);
mItemView = ((LayoutInflater) getActivity().getSystemService
(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.map_marker_layout, container, true);

mIconGenerator.setContentView(mItemView);
mIconGenerator.setBackground(null);
}

@Override
protected void onBeforeClusterItemRendered(VendorMapItem vendor, MarkerOptions markerOptions) {
// Draw a single vendor.
Bitmap icon;
if (null == selectedItem || !vendor.getPosition().equals(selectedItem.getPosition()))
{
icon = mIconGenerator.makeIcon();
} else {
icon = mSelectedIconGenerator.makeIcon();
}
markerOptions.title(vendor.getTitle());
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
}

@Override
protected void onBeforeClusterRendered(Cluster<VendorMapItem> cluster, MarkerOptions markerOptions) {
// Draw multiple vendors clustered...
Bitmap icon = mIconGenerator.makeIcon();
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
}

@Override
protected boolean shouldRenderAsCluster(Cluster cluster) {
// Always render clusters.
return cluster.getSize() > 1;
}
}

通常会显示聚类项目,也会显示非聚类项目,无论是否选中。我有另一个 View 显示列表中的所有位置数据,而我的远程位置只显示在那里。

知道我做错了什么吗?

最佳答案

愚蠢。

基本上我调用 map.clear() 的次数太多了。我想如果 map 上绘制的所有内容都是由聚类器控制的引脚,则无需调用 clear。一旦删除了 clear() 调用,我的图钉就会再次出现。

关于Android Maps ClusteredMarkers - 不显示未聚类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30709028/

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