Reputation: 6155
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.
Upvotes: 4
Views: 2500
Reputation: 24848
Try this way,hope this will help you to solve your problem.
1.Download Latest AndroidQuery jar from here
2.Put this jar to your libs folder and right click on jar and Build Path -> Add to bulid path.
3.How to use see this example:
AQuery androidQuery = new AQuery(this);
androidQuery.ajax(url.trim(), Bitmap.class, 0, new AjaxCallback<Bitmap>() {
@Override
public void callback(String url, Bitmap object, AjaxStatus status) {
super.callback(url, object, status);
googleMap.addMarker(new MarkerOptions().title("yourtitle").icon(BitmapDescriptorFactory.fromBitmap(object)).position(new LatLng(yourlatitude), Double.parseDouble(yourlongitude))));
}
});
Upvotes: 0
Reputation: 7439
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.
Upvotes: 1