Android地图实用工具:来自url的图片

我正在使用卓越的Android Maps Utility库在地图上显示带有群集的自定义标记。 它工作的很好,很容易定制。

我的问题是如何将本地资源从演示(R.drawable.image_demo)更改为来自URL的图像。 我正在使用通用图像加载程序在imageViewasynchronous加载此图像,但问题是图像不加载在相应的标记上。

任何人都知道任何例子?

这是在DefaultClusterRender类中下载和加载图像的代码。 提前致谢。

@Override protected void onBeforeClusterItemRendered(MapFoto mapFoto, MarkerOptions markerOptions) { // Draw a single person. // Set the info window to show their name. // mImageView.setImageResource(R.drawable.barcelona); // mImageView.setScaleType(ScaleType.CENTER_CROP); Log.d("", "--- url: " + mapFoto.getPictureUrl()); ImageLoader.getInstance().displayImage(mapFoto.getPictureUrl(), mImageView, BlipointApp.optionsAvatarImage, new ImageLoadingListener() { @Override public void onLoadingStarted(String imageUri, View view) { } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { } @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { mImageView.setImageBitmap(loadedImage); mImageView.setScaleType(ScaleType.CENTER_CROP); } @Override public void onLoadingCancelled(String imageUri, View view) { } }); Bitmap icon = mIconGenerator.makeIcon(); markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)).title(mapFoto.getName()); } 

Solutions Collecting From Web of "Android地图实用工具:来自url的图片"

我有使用UIL类似的问题,并不是所有的图像都加载。 每次我运行地图活动,并放大到群集有不同的标记/群集,没有图像。 只显示标准的标记/群集图标。

最后经过两天的尝试和尝试,它工作正常。 暂时我已经转到毕加索图书馆,看看它是否可以工作,但我遇到类似的问题,无法完成。 除了毕加索以外,所有从网页(URL)加载的图像都旋转了90度。 我无法弄清楚为什么。 根据我在网上发现的一些post,可能不得不对设备做些什么,我正在使用三星Galaxy S5设备进行testing。 但不知道….

这里有一些笔记我如何做到这一点:我创build了一个ImageView的HardRefSimpleImageLoadingListener ,它将存在,直到UIL加载过程完成。 如果没有硬引用ImageView ,onLoadingCancelled将被调用,加载将无法完成。 我还创build了包含图标生成器的Marker,ImageView和位图的对象ClusterMarkerTargetClusterItemMarkerTarget 。 我也把它们放到HashSets myClusterItemMarkerTargetsmyClusterMarkerTargets以防止垃圾收集。

也许它可以用于某人。

这里有一些代码:

  @Override protected void onClusterItemRendered(ReportItem clusterItem, Marker marker) { final ClusterItemMarkerTarget pm_ClusterItem = new ClusterItemMarkerTarget(marker); myClusterItemMarkerTargets.add(pm_ClusterItem); HardRefSimpleImageLoadingListener loadingListener = new HardRefSimpleImageLoadingListener() { @Override public void onLoadingFailed(String s, View view, FailReason failReason) { myClusterItemMarkerTargets.remove(pm_ClusterItem); } @Override public void onLoadingComplete(String s, View view, Bitmap bitmap) { mClusterItemImageView.setImageBitmap(bitmap); pm_ClusterItem.myIcon_cluster = mClusterItemIconGenerator.makeIcon(); pm_ClusterItem.mMarker.setIcon(BitmapDescriptorFactory.fromBitmap(pm_ClusterItem.myIcon_cluster)); myClusterItemMarkerTargets.remove(pm_ClusterItem); } @Override public void onLoadingCancelled(String s, View view) { myClusterItemMarkerTargets.remove(pm_ClusterItem); } }; ImageLoader.getInstance().displayImage(clusterItem.picPath, pm_ClusterItem.myClusterItemImageView , loadingListener ); } @Override protected void onClusterRendered(Cluster<ReportItem> cluster, Marker marker) { int i=0; clustersize = cluster.getSize(); final ClusterMarkerTarget pm_Cluster = new ClusterMarkerTarget(marker, cluster); myClusterMarkerTargets.add(pm_Cluster); for (ReportItem r : cluster.getItems()) { // Draw 1 at most. if (i == 1 ) { break; } HardRefSimpleImageLoadingListener loadingListener = new HardRefSimpleImageLoadingListener() { @Override public void onLoadingFailed(String s, View view, FailReason failReason) { myClusterMarkerTargets.remove(pm_Cluster); } @Override public void onLoadingComplete(String s, View view, Bitmap bitmap) { mClusterImageView.setImageBitmap(bitmap); // = (ImageView) view; //pm.myClusterImageView; pm_Cluster.myIcon_clusterItem = mClusterIconGenerator.makeIcon(String.valueOf(clustersize)); pm_Cluster.myMarker.setIcon(BitmapDescriptorFactory.fromBitmap(pm_Cluster.myIcon_clusterItem)); myClusterMarkerTargets.remove(pm_Cluster); } @Override public void onLoadingCancelled(String s, View view) { myClusterMarkerTargets.remove(pm_Cluster); } }; ImageLoader.getInstance().displayImage(r.picPath, pm_Cluster.myClusterImageView, loadingListener); i++; } } 

更多:

 //Set for holding a reference to marker targets --> targets won't get carbage collected during looping and loading images Set<ReportRenderer.ClusterItemMarkerTarget> myClusterItemMarkerTargets = new HashSet<>(); Set<ReportRenderer.ClusterMarkerTarget> myClusterMarkerTargets = new HashSet<>(); 

更多:

 public ReportRenderer(ClusterManager<ReportItem> mClusterManager, GoogleMap map) { super(MyApplication.getContext(), map, mClusterManager); mDimension = (int) MyApplication.getContext().getResources().getDimension(R.dimen.custom_report_image); mPadding = (int) MyApplication.getContext().getResources().getDimension(R.dimen.custom_report_padding); // initialize cluster icon generator View multiReport = inflater.inflate(R.layout.multi_report, null); mClusterImageView = (ImageView) multiReport.findViewById(R.id.image_report); mClusterIconGenerator = new IconGenerator(MyApplication.getContext()); mClusterIconGenerator.setContentView(multiReport); // initialize cluster item icon generator mClusterItemImageView = new ImageView(MyApplication.getContext()); mClusterItemImageView.setLayoutParams(new ViewGroup.LayoutParams(mDimension, mDimension)); mClusterItemImageView.setPadding(mPadding, mPadding, mPadding, mPadding); mClusterItemIconGenerator = new IconGenerator(MyApplication.getContext()); mClusterItemIconGenerator.setContentView(mClusterItemImageView); // initialize image loader options = new DisplayImageOptions.Builder() .showImageOnLoading(R.drawable.loading) .showImageForEmptyUri(R.drawable.warning) .showImageOnFail(R.drawable.fail) .cacheInMemory(true) .cacheOnDisk(true) .considerExifParams(true) //.bitmapConfig(Bitmap.Config.RGB_565) .build(); config = new ImageLoaderConfiguration.Builder(MyApplication.getContext()) .defaultDisplayImageOptions(options) .build(); ImageLoader.getInstance().init(config); } 

更多:

 //cluster marker with image loaded by Ultimate Image Loader class ClusterMarkerTarget { Marker myMarker; ImageView myClusterImageView; public ClusterMarkerTarget(Marker marker, Cluster<ReportItem> cluster) { myMarker = marker; View multiReport = inflater.inflate(R.layout.multi_report, null); myClusterImageView = (ImageView) multiReport.findViewById(R.id.image_report); } } //cluster item marker with image loaded by Ultimate Image Loader class ClusterItemMarkerTarget { Marker mMarker; ImageView myClusterItemImageView; public ClusterItemMarkerTarget(Marker marker) { mMarker = marker; myClusterItemImageView = new ImageView(MyApplication.getContext());//mClusterItemImageView; myClusterItemImageView.setLayoutParams(new ViewGroup.LayoutParams(mDimension, mDimension)); int padding = (int) MyApplication.getContext().getResources().getDimension(R.dimen.custom_report_padding); myClusterItemImageView.setPadding(padding, padding, padding, padding); } } 

最后:

  class HardRefSimpleImageLoadingListener extends SimpleImageLoadingListener { public ImageView mView; @Override public void onLoadingStarted(String imageUri, View view) { mView = (ImageView) view; } }