我使用here的Google Maps Android標記羣集實用程序,我從我的服務器收到的列表中添加了一堆項目(約700)。我已經解決了最初的錯誤,並且可以看到這些簇,然後放大它們,並將它們視爲單個標記。但是,有一些項目與其他項目相距甚遠,所以即使在最大縮小範圍內,它們也不會聚集在一起。出於某種原因,這些項目不會顯示在我的地圖上 - 不是當我放大時,而是縮小時。Android地圖ClusteredMarkers - 不顯示非集羣?
我檢查了座標,它們是真實的,在我開始使用集羣之前,我可以看到這些項目沒有問題,所以我假設我在集羣代碼中做了一些錯誤。
下面是一些代碼:
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;
}
}
一般而言羣集項目被示出,並且也declustered的,是否SEL是否受到影響。我有另一個視圖顯示列表中的所有位置數據,而我的遠程位置在那裏顯示的只是鰭。
任何想法我做錯了什麼?
您可以用於在地圖上添加集羣 –
感謝@Pratik,但是我已經使用了源中的集羣機制。當它們從不聚集在一起時,它不會繪製非聚集的單個項目,我無法弄清楚原因。 – Kibi