Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

android + universal image loader : show custom marker with image in google map

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

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

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...