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

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

问题描述

我的工作,有谷歌地图在其应用程序。在地图默认的标记是可见的,但我必须做的是让来自Facebook的网址一个图像,然后显示它在谷歌地图上。我使用的通用图像装载样本,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);

在code是简单的 displayImage()接受两个参数,第一个是 stringImageUrl (事先知情同意的URL)的第二是的ImageView (在布局中的ImageView对象)的。照片
现在为什么我需要的ViewImage对象,如果我必须展示形象map.Well ImageLoader的对象不从任何其功能不返回位图图像,首先我用了ImageView的设置从网址的ImageView所获取的图像,然后获取图像的位图。
我所做的是这样的事情。

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());

在我得到了图像中的BitmapDesc​​riptor,它很容易设置的标志。

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);

但问题是,这是不是WORKING.Image即将在的ImageView 对象,但没能得到它的标记

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

推荐答案

我建议你,就像一个魅力不同的方式:Android的查询

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

您可以从这里下载该jar文件code.google.com / P / Android的查询/下载/列表

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

AQuery androidAQuery=new AQuery(this);

作为一个例子:

As an example:

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

使用上述code,可直接显示您的图片,通过URL。现在低于code是从URL中得到位图直接:

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.

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

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