android + 通用图像加载器:在谷歌地图中显示带有图像的自定义标记 [英] android + universal image loader : show custom marker with image in google map

查看:30
本文介绍了android + 通用图像加载器:在谷歌地图中显示带有图像的自定义标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个包含谷歌地图的应用程序.地图中的默认标记是可见的,但我要做的是从 facebook url 获取图像,然后将其显示在谷歌地图上.我正在使用universal-image-loader-sample-1.8.6.apk"来使用 url 加载图像.

现在要加载图像,我正在这样做.

I am working on an application that has google map in it. The default marker in the map is visible but what i have to do is to get a image from the facebook url and then show it on the google map. I am using "universal-image-loader-sample-1.8.6.apk" to load the images using the url.

Now to load a image i am doing this.

ImageLoader imageLoader;
imageLoader = ImageLoader.getInstance();
ImageLoaderConfiguration ilc = ImageLoaderConfiguration.createDefault(this);
imageLoader.init(ilc);
ImageView imageView = (ImageView)findViewById(R.id.friend_pic);
imageLoader.displayImage(stringImageUrl, imageView);

代码很简单 displayImage() 接受两个参数,第一个是 stringImageUrl (图片的 url) 第二个是 imageView (布局中的 ImageView 对象).

现在为什么我需要 ViewImage 对象,如果我必须在地图上显示图像.那么 ImageLoader 对象不返回位图图像从它的任何函数到首先我使用 ImageView 将获取的图像从 url 设置为 imageview,然后在 Bitmap 中获取图像.
我所做的就是这样.

The code is simple the displayImage() accepts two argument ,first is stringImageUrl (the url of the pic) second is imageView (ImageView object in the layout).

Now why i need the ViewImage object if i have to show image on map.Well ImageLoader object does not returns bitmap image from any of its function to first i used the ImageView to set the fetched image from url to imageview and then get the image in Bitmap.
What i did is something like this.

Drawable drawble = imageView.getDrawable();
BitmapDescriptor icon=BitmapDescriptorFactory.fromBitmap(((BitmapDrawable)drawble).getBitmap());

一旦我在 BitmapDescriptor 中获得图像,就可以轻松地将其设置在标记中.

Once i got the image in the BitmapDescriptor , its easy to set it in marker.

Marker location = googleMap.addMarker(new MarkerOptions().visible(true)
                .title(stringName).position(position).icon(icon);

但问题是,这不起作用.图像进入 imageView 对象,但无法将其发送到 Marker.

but the problem is , THIS IS NOT WORKING.Image is coming in imageView object but not able to get it to Marker.

推荐答案

我向您推荐一种与众不同的方法:Android Query.

I recommend you a different way that works like a charm: Android Query.

您可以从这里下载该 jar 文件:http://code.google.com/p/android-query/downloads/list

You can download that jar file from here: http://code.google.com/p/android-query/downloads/list

AQuery androidAQuery=new AQuery(this);

举个例子:

androidAQuery.id(YOUR IMAGEVIEW).image(YOUR IMAGE TO LOAD, true, true, getDeviceWidth(), ANY DEFAULT IMAGE YOU WANT TO SHOW);

使用上面的代码,您可以通过 url 直接显示您的图像.现在下面的代码是直接从url获取Bitmap:

Using above code you can directly show your Image through url. Now below code is to get Bitmap Directly from the url:

androidAQuery.ajax(YOUR IMAGE URL,Bitmap.class,0,new AjaxCallback<Bitmap>(){
                        @Override
                        public void callback(String url, Bitmap object, AjaxStatus status) {
                            super.callback(url, object, status);

                            //You will get Bitmap from object.
                        }

                    });

它非常快速和准确,使用它你可以在加载时找到更多的功能,比如动画;如果需要,获取位图;等

It's very fast and accurate, and using this you can find many more features like Animation when loading; getting a bitmap, if needed; etc.

这篇关于android + 通用图像加载器:在谷歌地图中显示带有图像的自定义标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆