Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有动态图像URL的Android Google地图群集项目标记-使用所有标记覆盖URL_Android_Google Maps_Markerclusterer - Fatal编程技术网

带有动态图像URL的Android Google地图群集项目标记-使用所有标记覆盖URL

带有动态图像URL的Android Google地图群集项目标记-使用所有标记覆盖URL,android,google-maps,markerclusterer,Android,Google Maps,Markerclusterer,在my app having cluster on map中,顶部/主要簇标记显示总标记计数,单击显示所有子簇项目标记 在集群项目(子集群标记)中,显示具有不同颜色的圆形背景,中间显示来自URL的图像(从web服务响应获取),集群项目正确显示图像,但 我的问题是,在刷新最后一个响应图像URL后,将覆盖所有标记图像,这意味着 所有群集项显示相同的图像,而不是不同的图像 请任何人都可以帮助解决这个问题。我的代码如下 private class RenderClusterInfoWindo

在my app having cluster on map中,顶部/主要簇标记显示总标记计数,单击显示所有子簇项目标记

在集群项目(子集群标记)中,显示具有不同颜色的圆形背景,中间显示来自URL的图像(从web服务响应获取),集群项目正确显示图像,但 我的问题是,在刷新最后一个响应图像URL后,将覆盖所有标记图像,这意味着 所有群集项显示相同的图像,而不是不同的图像

请任何人都可以帮助解决这个问题。我的代码如下

      private class RenderClusterInfoWindow extends DefaultClusterRenderer<ModelClusterBikeList> {

    private final IconGenerator mClusterIconGenerator = new IconGenerator(getActivity());
    private final IconGenerator iconGenerator = new IconGenerator(getActivity());
    ImageView imageView;
    int markerWidth;
    int markerHeight;
    private DisplayImageOptions options;

    RenderClusterInfoWindow(Activity context, GoogleMap map, ClusterManager<ModelClusterBikeList> clusterManager) {
        super(context, map, clusterManager);

        // Main inflate view it show number data available inside cluster
        View multiProfile = getLayoutInflater().inflate(R.layout.inflate_cluster, null);
        mClusterIconGenerator.setContentView(multiProfile);

        markerWidth = (int) context.getResources().getDimension(R.dimen.custom_profile_image);
        markerHeight = (int) context.getResources().getDimension(R.dimen.custom_profile_image);

        // inflator its show image from the response url. (cluster item)
        View clusterITEM = getLayoutInflater().inflate(R.layout.inflate_cluster_item, null);
        iconGenerator.setContentView(clusterITEM);
        imageView = clusterITEM.findViewById(R.id.imageClusterPIN);


        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(markerWidth, markerHeight);
        layoutParams.gravity = Gravity.CENTER;
        imageView.setLayoutParams(layoutParams);


        ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(getActivity()));

        options = new DisplayImageOptions.Builder()
                .showImageForEmptyUri(R.mipmap.image_icn)
                .showImageOnFail(R.mipmap.image_icn)
                .cacheInMemory(false)
                .cacheOnDisk(true)
                .considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .build();
    }

    @Override
    protected boolean shouldRenderAsCluster(Cluster<ModelClusterBikeList> cluster) {

        if (getActivity() != null) {
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (googleMap.getCameraPosition().zoom > 19.0) {
                        setClusterSize = 2;
                    } else {
                        setClusterSize = 4;
                    }
                }
            });
        }

        if (setClusterSize == 2) {
            return cluster.getSize() > cluster.getSize();
        } else {
            return cluster.getSize() > setClusterSize;
        }

    }

    @Override
    protected void onClusterRendered(Cluster<ModelClusterBikeList> cluster, Marker marker) {
        super.onClusterRendered(cluster, marker);
    }

    @Override
    protected void onBeforeClusterItemRendered(ModelClusterBikeList item, MarkerOptions markerOptions) {


        iconGenerator.setBackground(
                ContextCompat.getDrawable(getActivity(), R.drawable.round_asset));


        ImageLoader.getInstance().displayImage(item.getAssets_img_url(), imageView, options);

        // Issue is here , overwrite image url here with all marker./cluster item.
        Bitmap icon = iconGenerator.makeIcon(item.getAssets_img_url());
        markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));

        markerOptions.title(item.getId());
        markerOptions.draggable(true);

        super.onBeforeClusterItemRendered(item, markerOptions);
    }

    @Override
    protected void onBeforeClusterRendered(Cluster<ModelClusterBikeList> cluster, MarkerOptions markerOptions) {

        mClusterIconGenerator.setBackground(null);
        Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
        markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));

    }

    @Override
    protected void onClusterItemRendered(ModelClusterBikeList clusterItem, Marker marker) {
        super.onClusterItemRendered(clusterItem, marker);
    }
}
私有类RenderClusterInfo窗口扩展了DefaultClusterRenderer{
专用最终IconGenerator mClusterIconGenerator=新IconGenerator(getActivity());
专用最终IconGenerator IconGenerator=新IconGenerator(getActivity());
图像视图图像视图;
int markerWidth;
国际马克黑度;
私有显示图像选项;
RenderClusterInfo窗口(活动上下文、Google地图、ClusterManager ClusterManager){
超级(上下文、地图、群集管理器);
//主充气视图显示集群内可用的编号数据
View multiProfile=getLayoutInflater().inflate(R.layout.inflate_集群,null);
setContentView(多功能文件);
markerWidth=(int)context.getResources().getDimension(R.dimen.custom\u profile\u image);
markerHeight=(int)context.getResources().getDimension(R.dimen.custom\u profile\u image);
//充气器显示响应url中的图像。(群集项目)
View clusterITEM=GetLayoutFlater().inflate(R.layout.inflate\u cluster\u项,null);
iconGenerator.setContentView(clusterITEM);
imageView=clusterITEM.findViewById(R.id.imageClusterPIN);
FrameLayout.LayoutParams LayoutParams=新的FrameLayout.LayoutParams(markerWidth,markerHeight);
layoutParams.gravity=gravity.CENTER;
setLayoutParams(layoutParams);
ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(getActivity());
选项=新建DisplayImageOptions.Builder()
.showImageForEmptyUri(R.mipmap.image\u icn)
.showImageOnFail(R.mipmap.image\u icn)
.cacheInMemory(false)
.cacheOnDisk(真)
.considerExifParams(真)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
}
@凌驾
受保护的布尔值shouldRenderAsCluster(群集){
如果(getActivity()!=null){
getActivity().runOnUiThread(新的Runnable()){
@凌驾
公开募捐{
if(googleMap.getCameraPosition().zoom>19.0){
setClusterSize=2;
}否则{
setClusterSize=4;
}
}
});
}
如果(setClusterSize==2){
返回cluster.getSize()>cluster.getSize();
}否则{
返回cluster.getSize()>setClusterSize;
}
}
@凌驾
受保护的void onClusterRendered(群集、标记){
super.onClusterRendered(集群、标记);
}
@凌驾
在呈现前ClusterItem(ModelClusterBikeList项、MarkeOptions MarkeOptions)时受保护的空{
iconGenerator.backbackground(
getDrawable(getActivity(),R.drawable.round_asset));
ImageLoader.getInstance().displayImage(item.getAssets\u img\u url(),imageView,选项);
//此处存在问题,请使用所有标记覆盖此处的图像url。/cluster项。
位图图标=iconGenerator.makeIcon(item.getAssets\u img\u url());
图标(BitmapDescriptorFactory.fromBitmap(图标));
markerOptions.title(item.getId());
markerOptions.draggable(true);
super.onBeforeClusterItemRendered(项目、标记选项);
}
@凌驾
在呈现群集之前受保护的void(群集群集、标记选项标记选项){
mclustericonggenerator.setBackground(空);
位图icon=mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize());
图标(BitmapDescriptorFactory.fromBitmap(图标));
}
@凌驾
ClusterItemRendered上受保护的void(ModelClusterBikeList clusterItem、Marker){
super.onClusterItemRendered(聚类项目、标记);
}
}

我还尝试将“onBeforeClusterItemRendered”的所有代码放入onClusterItemRendered中,但得到相同的结果,用所有cluter项覆盖最后一个url。

Hello@Topsy根据以下内容更改代码,这对您很有用

首先用以下代码替换onBeforeClusterItemRendered方法

   @Override
   protected void onBeforeClusterItemRendered(ModelClusterBikeList item, MarkerOptions 
   markerOptions) {

        icon = iconGenerator.makeIcon();
        markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)).
                                                      title(item.getAssets_img_url());

        markerOptions.title(item.getId());
        markerOptions.draggable(true);

        super.onBeforeClusterItemRendered(item, markerOptions);
   }
   @Override
   protected void onClusterItemRendered(ModelClusterBikeList clusterItem, Marker 
   marker) {


     if (getActivity() != null) {

         Glide.with(getActivity())
              .asBitmap()
              .load(clusterItem.getAssets_img_url())
              .error(R.drawable.ic_launcher)
              .diskCacheStrategy(DiskCacheStrategy.ALL)
              .into(new CustomTarget<Bitmap>() {
               @Override
               public void onResourceReady(@NonNull Bitmap resource, @Nullable 
               Transition<? super Bitmap> transition) {

                   try {
                      if (googleMap != null) {

                            iconGenerator.setBackground(
                            ContextCompat.getDrawable(getActivity(), 
                                                        R.drawable.round_asset));

                            imageView.setImageBitmap(resource);
                            imageView.buildDrawingCache();
                            Bitmap icon = iconGenerator.makeIcon();
                             if (icon != null) {
                             marker.setIcon(BitmapDescriptorFactory.fromBitmap(icon));
                           }
                         }
                     } catch (Exception e) {
                              e.printStackTrace();
                      }
                 }

                @Override
                public void onLoadCleared(@Nullable Drawable placeholder) {
                }
            });
          }

      }
然后用以下代码替换onClusterItemRendered方法

   @Override
   protected void onBeforeClusterItemRendered(ModelClusterBikeList item, MarkerOptions 
   markerOptions) {

        icon = iconGenerator.makeIcon();
        markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)).
                                                      title(item.getAssets_img_url());

        markerOptions.title(item.getId());
        markerOptions.draggable(true);

        super.onBeforeClusterItemRendered(item, markerOptions);
   }
   @Override
   protected void onClusterItemRendered(ModelClusterBikeList clusterItem, Marker 
   marker) {


     if (getActivity() != null) {

         Glide.with(getActivity())
              .asBitmap()
              .load(clusterItem.getAssets_img_url())
              .error(R.drawable.ic_launcher)
              .diskCacheStrategy(DiskCacheStrategy.ALL)
              .into(new CustomTarget<Bitmap>() {
               @Override
               public void onResourceReady(@NonNull Bitmap resource, @Nullable 
               Transition<? super Bitmap> transition) {

                   try {
                      if (googleMap != null) {

                            iconGenerator.setBackground(
                            ContextCompat.getDrawable(getActivity(), 
                                                        R.drawable.round_asset));

                            imageView.setImageBitmap(resource);
                            imageView.buildDrawingCache();
                            Bitmap icon = iconGenerator.makeIcon();
                             if (icon != null) {
                             marker.setIcon(BitmapDescriptorFactory.fromBitmap(icon));
                           }
                         }
                     } catch (Exception e) {
                              e.printStackTrace();
                      }
                 }

                @Override
                public void onLoadCleared(@Nullable Drawable placeholder) {
                }
            });
          }

      }
@覆盖
ClusterItemRendered上受保护的空(ModelClusterBikeList clusterItem,标记
(标记){
如果(getActivity()!=null){
Glide.with(getActivity())
.asBitmap()
.load(clusterItem.getAssets\u img\u url())
.错误(R.drawable.ic_启动器)
.diskCacheStrategy(diskCacheStrategy.ALL)
.into(新的CustomTarget(){
@凌驾
public void onResourceReady(@NonNull位图资源,@Nullable

如果ans对你有帮助,你能接受它吗?所以,其他人可以使用它