How to add Multiple overlays to Map?
<p>Hi dudes I am trying to display fb friends pics on map and I am using for loop to add overlays it taking too much time please help me thanks in advance.....</p>

<p>Here my main activity <code>GoogleMapsActivity</code></p>

<pre><code>/********************************************************************
 * 
 * Desc : This class to display google map by using android google map SDK(library)
 * @extends : MapActivity
 * Author : Bhaskar Reddy
 * ******************************************************************
 */

package com.fb.demo;

import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

import com.facebook.android.Facebook;
import com.facebook.android.FacebookError;
import com.facebook.android.Util;
import com.fb.demo.FriendsGetProfilePics.GetProfilePicAsyncTask;
import com.fb.demo.bean.FriendBean;
import com.fb.demo.extras.MyFaceBook;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class GoogleMapsActivity extends MapActivity {

    public static List&lt;FriendBean&gt; friendBeans;
    Facebook mFacebook;
    Geocoder coder;
    List&lt;Overlay&gt; mapOverlays;
    ListView dummy;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // GlobalState gs = (GlobalState) getApplication();
        // friendBeans = gs.getGlobal_friends();
        setContentView(R.layout.map);
        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);

        // Satellite mode
        mapView.setSatellite(true);
        mapOverlays = mapView.getOverlays();

        // getting Map view reference from xml and assigning to MapView object

        mFacebook = MyFaceBook.mFacebook;

        HelloItemizedOverlay itemizedoverlay = null;
        GeoPoint point = null;
        MyOverLayItem overlayitem = null;
        // BitmapDrawable bitmapDrawable = null;
        Drawable drawable = null;

        // BitmapDrawable bitmapDrawable = null;

        coder = new Geocoder(this);
        JSONObject json_data = null;

        double latitude = 0.0, longitude = 0.0;
        List&lt;Address&gt; address = null;
        JSONArray jArray = null;
        String TAG = "MAP";
        FriendsGetProfilePics fPics = new FriendsGetProfilePics();
        GetProfilePicAsyncTask getPic = fPics.new GetProfilePicAsyncTask();

        Bundle parameters = new Bundle();
        String fql = "SELECT uid,pic_square,name,current_location FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";
        parameters.putString("format", "json");
        parameters.putString("query", fql);
        parameters.putString("access_token",
                MyFaceBook.mFacebook.getAccessToken());

        if (MyFaceBook.mFacebook.isSessionValid()) {
            parameters.putString("access_token",
                    MyFaceBook.mFacebook.getAccessToken());
        }
        try {
            String test = Util
                    .openUrl("https://api.facebook.com/method/fql.query",
                            "GET", parameters).replace("[", "{'data':[")
                    .replace("]", "]}");
            Log.d("FQL Testing", test.toString());
            JSONObject jobj = Util.parseJson(test);
            jArray = jobj.getJSONArray("data");
        } catch (Exception e) {
        } catch (FacebookError e) {
            e.printStackTrace();
        }

        for (int i = 0; i &lt; jArray.length(); i++) {
            String homeTown = null;
            try {
                json_data = jArray.getJSONObject(i);
                /** Checking location available or not */

                if (json_data.getString("current_location") != null) {
                    JSONObject temp = Util.parseJson(json_data
                            .getString("current_location"));
                    Log.d("loc", temp.toString());
                    if (temp.has("name")) {
                        homeTown = temp.getString("name");
                        Log.d("Town", homeTown);
                        /** Finding latitude and longitude */

                        try {

                            address = coder.getFromLocationName(homeTown, 5);
                            if (address == null)
                                Log.d(TAG, "Latitude and longitude not found");
                            else {
                                Address location = address.get(0);
                                latitude = location.getLatitude();
                                longitude = location.getLongitude();
                            }

                        } catch (Exception e) {
                            Log.d(TAG, e.getMessage());
                            Log.d(TAG, "MY_ERROR :Address Not Found");

                        }
                    }

                    if (homeTown != null) {
                        drawable = new BitmapDrawable(
                                getPic.getBitmap(json_data
                                        .getString("pic_square")));
                        drawable.setBounds(-drawable.getIntrinsicWidth() / 2,
                                -drawable.getIntrinsicHeight(),
                                drawable.getIntrinsicWidth() / 2, 0);

                        point = new GeoPoint((int) (latitude * 1E6),
                                (int) (longitude * 1E6));

                        itemizedoverlay = new HelloItemizedOverlay(drawable,
                                this);
                        overlayitem = new MyOverLayItem(point, "Hi "
                                + json_data.getString("name"), homeTown,
                                json_data.getString("uid"));

                        overlayitem.setMarker(drawable);
                        itemizedoverlay.addOverlay(overlayitem);
                        mapOverlays.add(itemizedoverlay);

                    }

                }
            } catch (Exception e) {
            } catch (FacebookError e) {
                e.printStackTrace();
            }

        }

    }

    class MyOverLayItem extends OverlayItem {

        private String uid;

        public String getUid() {
            return uid;
        }

        public void setUid(String uid) {
            this.uid = uid;
        }

        public MyOverLayItem(GeoPoint point, String title, String snippet,
                String uid) {
            super(point, title, snippet);
            this.uid = uid;

        }

    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }



}
</code></pre>

<p>Here My ItemizedOverLay.
<code>HelloItemizedOverlay</code>:</p>

<pre><code>package com.fb.demo;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;
import com.fb.demo.extras.MyFaceBook;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class HelloItemizedOverlay extends ItemizedOverlay&lt;OverlayItem&gt; {
    Facebook mFacebook;
    private ArrayList&lt;OverlayItem&gt; mOverlays = new ArrayList&lt;OverlayItem&gt;();

    Context mContext;

    /*
     * This constructor will be called from HellowGoogleMapsActivity here we are
     * calling super constructor to draw image
     */
    public HelloItemizedOverlay(Drawable defaultMarker) {
        super(boundCenterBottom(defaultMarker));
        mFacebook = MyFaceBook.mFacebook;
    }

    public void addOverlay(OverlayItem overlay) {
        mOverlays.add(overlay);
        populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
        return mOverlays.get(i);
    }

    @Override
    public int size() {
        return mOverlays.size();
    }

    public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
        super(boundCenterBottom(defaultMarker));
        mContext = context;
    }

    @Override
    protected boolean onTap(int index) {
        final GoogleMapsActivity.MyOverLayItem item = (GoogleMapsActivity.MyOverLayItem) mOverlays
                .get(index);
        AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
        dialog.setTitle(item.getTitle());
        dialog.setMessage(item.getSnippet());
        dialog.show();

        Bundle params = new Bundle();
        params.putString("to", item.getUid());
        MyFaceBook.mFacebook.dialog(mContext, "feed", params,
                new PostDialogListener());

        return true;
    }

    public abstract class BaseDialogListener implements DialogListener {
        @Override
        public void onFacebookError(FacebookError e) {
            e.printStackTrace();
        }

        @Override
        public void onError(DialogError e) {
            e.printStackTrace();
        }

        @Override
        public void onCancel() {
        }
    }

    public class PostDialogListener extends BaseDialogListener {
        @Override
        public void onComplete(Bundle values) {
            final String postId = values.getString("post_id");
            if (postId != null) {
                // showToast("Message posted on the wall.");
            } else {
                // showToast("No message posted on the wall.");
            }
        }
    }


}
</code></pre>

<p>This Method to get bit map.
<code>getBitMap()</code>:</p>

<pre><code> public Bitmap getBitmap(String url) {
            Log.d("getBitmap", "getBitmap");
            Bitmap bm = null;
            try {
                URL aURL = new URL(url);
                URLConnection conn = aURL.openConnection();
                conn.connect();
                InputStream is = conn.getInputStream();
                BufferedInputStream bis = new BufferedInputStream(is);
                bm = BitmapFactory.decodeStream(new FlushedInputStream(is));
                bis.close();
                is.close();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (httpclient != null) {
                    httpclient.close();
                }
            }
            return bm;
        }

class FlushedInputStream extends FilterInputStream {
        public FlushedInputStream(InputStream inputStream) {
            super(inputStream);
        }
    }
</code></pre>
