Google Map Cluster with Url

pho*_*van 5 android google-maps markerclusterer android-glide

我使用Google的Android-map-utils库处理Google Map集群。就我而言,我使用Glide从URL加载图像:

@Override
        protected void onBeforeClusterItemRendered(final FeedsModel feedsModel, final MarkerOptions markerOptions) {
            // Draw a single person.
            // Set the info window to show their name.
            Glide
                    .with(mActivity.getApplicationContext())
                    .load(feedsModel.getImages().getThumbnail().getUrl())
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(new SimpleTarget<GlideDrawable>() {
                        @Override
                        public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                            mImageView.setImageDrawable(resource);
                            Bitmap icon = mIconGenerator.makeIcon();
                            Marker markerToChange = null;
                            for (Marker marker : mClusterManager.getMarkerCollection().getMarkers()) {
                                if (marker.getPosition().equals(feedsModel.getPosition())) {
                                    markerToChange = marker;
                                }
                            }
                            // if found - change icon
                            if (markerToChange != null) {
                                markerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon));
                            }
                        }
                    });
            Bitmap icon = mIconGenerator.makeIcon();
            markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
        }

        @Override
        protected void onBeforeClusterRendered(final Cluster<FeedsModel> cluster, final MarkerOptions markerOptions) {
            // Draw multiple people.
            // Note: this method runs on the UI thread. Don't spend too much time in here (like in this example).
            final List<Drawable> profilePhotos = new ArrayList<Drawable>(Math.min(4, cluster.getSize()));
            final int width = mDimension;
            final int height = mDimension;

            int i = 0;

            for (final FeedsModel p : cluster.getItems()) {
                // Draw 4 at most.
                i++;
                Glide
                        .with(mActivity.getApplicationContext())
                        .load(p.getImages().getThumbnail().getUrl())
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .into(new SimpleTarget<GlideDrawable>() {
                            @Override
                            public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                                resource.setBounds(0, 0, width, height);
                                profilePhotos.add(resource);
                                MultiDrawable multiDrawable = new MultiDrawable(profilePhotos);
                                multiDrawable.setBounds(0, 0, width, height);

                                mClusterImageView.setImageDrawable(multiDrawable);
                                Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
                                markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
                            }
                        });

                if (i == 4) break;
            }
            Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
            markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
        }
Run Code Online (Sandbox Code Playgroud)

通过上面的代码,我看到:放大或缩小时,“项目”和“群集”中的图像加载错误。我这是怎么了?

pho*_*van 4

最后,我找到了解决方案,我结合:

protected void onClusterItemRendered(FeedsModel clusterItem, Marker marker) 
protected void onClusterRendered(Cluster<FeedsModel> cluster, Marker marker)
Run Code Online (Sandbox Code Playgroud)

这些函数从 URL 加载图像

  • 您能分享一下这个问题的详细方法吗? (2认同)