Java 如何在android中使用不同ID获取url(异步任务)

Java 如何在android中使用不同ID获取url(异步任务),java,android,google-maps,android-asynctask,Java,Android,Google Maps,Android Asynctask,编辑:找到问题的解决方案。 json字符串输出为我的本地图像返回了错误的url 我刚接触安卓系统,正在努力完成这项任务 我想要的是得到地图上一个标记对应的图像。 此映射上的每个条目都有自己的映像,必须通过json从服务器加载 图像加载工作正常,但我没有正确的工作流程来获取一个条目所需的图像 到目前为止,我有一个解决方案可以在for循环中加载异步任务,但这不是正确的方法,因为应用程序拒绝在43个任务之后继续运行,并停止运行 “ECONNECTION超时” 那么,如何才能使asynctask脱离循环

编辑:找到问题的解决方案。 json字符串输出为我的本地图像返回了错误的url

我刚接触安卓系统,正在努力完成这项任务

我想要的是得到地图上一个标记对应的图像。 此映射上的每个条目都有自己的映像,必须通过json从服务器加载

图像加载工作正常,但我没有正确的工作流程来获取一个条目所需的图像

到目前为止,我有一个解决方案可以在for循环中加载异步任务,但这不是正确的方法,因为应用程序拒绝在43个任务之后继续运行,并停止运行 “ECONNECTION超时”

那么,如何才能使asynctask脱离循环呢

希望有人能帮忙?谢谢大家!

这是我的密码:

公共类MapsActivity扩展了AppCompatActivity在MapReadyCallback上的实现{

private GoogleMap mMap;

JSONArray contentJson;

String contentId;
String imageJsonUrl;
String userId;
Bitmap bmp;
LatLng latLng;
Marker m;
HashMap<Marker, String> hashMap;

int k = 0;

// check value for Request check
final int MY_LOCATION_REQUEST_CODE = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(myToolbar);

    getSupportActionBar().setDisplayShowTitleEnabled(false);

    if(this.getIntent().getExtras() != null) {
            try {
                contentJson = new JSONArray(this.getIntent().getStringExtra("contentJson"));
               // Log.v("TESTITEST", contentJson.toString());
            } catch (JSONException e) {
                Log.e("EXCEPTION", "unexpected JSON exception", e);
                e.printStackTrace();
            }
    }
}

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_maps, menu);
    return true;
}

public LatLng getLatLngPosition() {
    return new LatLng(0, 0);
}

/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {

    mMap = googleMap;

    //Ask for Permission. If granted show my Location
    if (ActivityCompat.checkSelfPermission(MapsActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {
        // Check Permissions Now
        ActivityCompat.requestPermissions(MapsActivity.this,
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                MY_LOCATION_REQUEST_CODE);
    } else {
        // permission has been granted, continue as usual
        mMap.setMyLocationEnabled(true);
    }

    PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
            getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {

            // TODO: Get info about the selected place.
            LatLng selectedLocation = place.getLatLng();
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(selectedLocation, 10f));
        }

        @Override
        public void onError(Status status) {
            // TODO: Handle the error.
            Log.i("PlaceSelectorError", "An error occurred: " + status);
        }
    });

    LatLng bonn = new LatLng(50.7323, 7.1847);
    LatLng cologne = new LatLng(50.9333333, 6.95);
    //mMap.addMarker(new MarkerOptions().position(bonn).title("Marker in Bonn"));

    // hash map for saving content id with marker
    hashMap = new HashMap<Marker, String>();

    if(contentJson != null) {

        if (this.getIntent().getStringExtra("contentId") == null) {
            // show all contents of my friends
            try {
                for (int i = 0; i < contentJson.length(); i++) {
                    JSONObject jsonInfo = contentJson.getJSONObject(i);

                    JSONArray contents = jsonInfo.getJSONArray("content");
                    // Log.v("contentslength", String.valueOf(contents.length()));

                    //get all contents of one user
                    for (int j = 0; j < contents.length(); j++) {
                        JSONObject eachcontent = contents.getJSONObject(j);
                        //Log.v("eachcontent", eachcontent.toString());
                        JSONObject location = eachcontent.getJSONObject("Location");
                        String contentId = eachcontent.getString("id");
                        String contentTitle = eachcontent.getString("title");
                        userId = eachcontent.getString("user_id");
                        latLng = new LatLng(Double.valueOf(location.getString("latitude")), Double.valueOf(location.getString("longitude")));
                        new MapImageLoadTask("http://192.168.63.35:1234/rest_app_users/getImage/", userId, contentId, contentTitle, latLng).execute();


                        Log.v("contentTitle", contentTitle);
                        //Log.v("m", m.toString());
                        //m = mMap.addMarker(new MarkerOptions().title(contentTitle).position(new LatLng(Double.valueOf(location.getString("latitude")), Double.valueOf(location.getString("longitude")))).icon(BitmapDescriptorFactory.fromBitmap(bmp)));
                    }
                }
            } catch (JSONException e) {
                Log.e("Exception", "unexpected JSON exception", e);
                e.printStackTrace();
            }
        }


        else {
            // if we only want to see a specific content
            try {

                for (int i = 0; i < contentJson.length(); i++) {
                    JSONObject jsonInfo = contentJson.getJSONObject(i);

                    JSONArray contents = jsonInfo.getJSONArray("content");

                    //get all contents of one user
                    for (int j = 0; j < contents.length(); j++) {
                        JSONObject eachcontent = contents.getJSONObject(j);
                        JSONObject location = eachcontent.getJSONObject("Location");
                        if(eachcontent.getString("id").equals(this.getIntent().getStringExtra("contentId"))) {

                            String contentId = eachcontent.getString("id");
                            String contentTitle = eachcontent.getString("title");
                            userId = eachcontent.getString("user_id");
                            latLng = new LatLng(Double.valueOf(location.getString("latitude")), Double.valueOf(location.getString("longitude")));
                          //  Log.v("LATLNG", contentId);
                            new MapImageLoadTask("http://192.168.63.35:1234/rest_app_users/getImage/", userId, contentId, contentTitle, latLng).execute();

                            continue;

                        }
                    }
                }
            } catch (JSONException e) {
                Log.e("LOGEDILOG", "unexpected JSON exception", e);
                e.printStackTrace();
            }
        }
    }

    mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
        @Override
        public void onMyLocationChange(Location location) {
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                    new LatLng(location.getLatitude(), location.getLongitude()), 10f));
            mMap.setOnMyLocationChangeListener(null);
        }
    });

    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {
            String id = hashMap.get(marker);
            Log.v("BITMAP", bmp.toString());
            try {
                Context context = getApplicationContext();
                Intent mapIntent = new Intent(getApplicationContext(), contentDetailActivity.class);
                mapIntent.putExtra("contentId", id);
                mapIntent.putExtra("contentJson", contentJson.toString());
                mapIntent.putExtra("userId", userId);
                String filename = "profileImage.png";
                FileOutputStream stream = context.openFileOutput(filename, Context.MODE_PRIVATE);
                bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);

                //Cleanup
                stream.close();
                mapIntent.putExtra("image", filename);

                startActivity(mapIntent);

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

public Marker[] addMarkers() {
    return null;
}

/**
 *  lets you load Image from external source via url
 */
public class MapImageLoadTask extends AsyncTask<Void, Void, Bitmap> {
    private final String LOG_TAG = MapImageLoadTask.class.getSimpleName();
    String url, userId, contentId, title;
    LatLng location;
    BufferedReader reader = null;

    public MapImageLoadTask(String url, String userId, String contentId, String title, LatLng location) {
        this.url = url;
        this.userId = userId;
        this.contentId = contentId;
        this.title = title;
        this.location = location;
    }

    private String getImageUrlFromJson(String imageJson) throws JSONException {

        JSONObject imageJsonOutput = new JSONObject(imageJson);
        imageJsonUrl = imageJsonOutput.getString("imageUrl");
        //Log.v(LOG_TAG, imageJsonUrl);
        return imageJsonUrl;
    }

    @Override
    protected Bitmap doInBackground(Void... params) {
        String imageJson = null;
        try {
            URL urlConnection = new URL(url + userId);
            HttpURLConnection connection = (HttpURLConnection) urlConnection
                    .openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            StringBuffer buffer = new StringBuffer();
            if (input == null) {
                // Nothing to do.
                //forecastJsonStr = null;
                return null;
            }

            reader = new BufferedReader(new InputStreamReader(input));

            String line;
            while ((line = reader.readLine()) != null) {
                // Since it's JSON, adding a newline isn't necessary (it won't affect parsing)
                // But it does make debugging a *lot* easier if you print out the completed
                // buffer for debugging.
                buffer.append(line + "\n");
            }

            if (buffer.length() == 0) {
                return null;
            }

            imageJson = buffer.toString();

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

        try {
            String jsonUrl = getImageUrlFromJson(imageJson);
            URL url = new URL(jsonUrl);
            bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());

            return bmp;
        }
        catch(Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Bitmap result) {
        super.onPostExecute(result);
        k +=1;
        Log.v("COUNTER", String.valueOf(k));
        m = mMap.addMarker(new MarkerOptions().title(title).position(location).icon(BitmapDescriptorFactory.fromBitmap(bmp)));
        hashMap.put(m, contentId);

    }
}
私有谷歌地图mMap;
JSONArray-contentJson;
字符串contentId;
字符串图像JSONURL;
字符串用户标识;
位图bmp;
LatLng LatLng;
标记m;
HashMap;
int k=0;
//请求检查的检查值
最终输入我的位置请求代码=3;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_映射);
//获取SupportMapFragment,并在地图准备好使用时收到通知。
SupportMapFragment mapFragment=(SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map);
getMapAsync(这个);
工具栏myToolbar=(工具栏)findViewById(R.id.my_工具栏);
设置支持操作栏(myToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
if(this.getIntent().getExtras()!=null){
试一试{
contentJson=newJSonarray(this.getIntent().getStringExtra(“contentJson”);
//Log.v(“TestTest”,contentJson.toString());
}捕获(JSONException e){
Log.e(“异常”,“意外JSON异常”,e);
e、 printStackTrace();
}
}
}
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.menu\u地图,菜单);
返回true;
}
公共LatLng getLatLngPosition(){
返回新板条(0,0);
}
/**
*一旦可用,就可以操纵贴图。
*当映射准备好使用时,将触发此回调。
*这是我们可以添加标记或线条、添加侦听器或移动摄影机的地方。在这种情况下,
*我们只是在澳大利亚悉尼附近加了一个标记。
*如果设备上未安装Google Play服务,系统将提示用户安装
*它位于SupportMapFragment内。此方法仅在用户
*已安装Google Play服务并返回应用程序。
*/
@凌驾
4月1日公开作废(谷歌地图谷歌地图){
mMap=谷歌地图;
//请求许可。如果允许,请显示我的位置
if(ActivityCompat.checkSelfPermission(MapsActivity.this、Manifest.permission.ACCESS\u FINE\u位置)
!=PackageManager.权限(已授予){
//现在检查权限
ActivityCompat.requestPermissions(MapsActivity.this,
新字符串[]{Manifest.permission.ACCESS\u FINE\u LOCATION},
我的位置请求代码);
}否则{
//已授予权限,请照常继续
mMap.setMyLocationEnabled(真);
}
PlaceAutocompleteFragment autocompleteFragment=(PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place\u autocomplete\u fragment);
autocompleteFragment.setOnPlaceSelectedListener(新的PlaceSelectionListener(){
@凌驾
已选定地点上的公共作废(地点){
//TODO:获取有关所选地点的信息。
LatLng selectedLocation=place.getLatLng();
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(selectedLocation,10f));
}
@凌驾
公共作废申报人(状态){
//TODO:处理错误。
Log.i(“PlaceSelectorError”,“发生错误:+状态”);
}
});
LatLng波恩=新LatLng(50.7323,7.1847);
LatLng科隆=新LatLng(50.9333333,6.95);
//mMap.addMarker(新的MarkerOptions().position(波恩).title(“波恩的标记”);
//用于使用标记保存内容id的哈希映射
hashMap=新的hashMap();
if(contentJson!=null){
if(this.getIntent().getStringExtra(“contentId”)==null){
//显示我朋友的所有内容
试一试{
for(int i=0;ipublic abstract class AsyncTask<Params, Progress, Result> {
    private static final String LOG_TAG = "AsyncTask";

    private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
    private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
    private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
    private static final int KEEP_ALIVE = 1;

    private static final ThreadFactory sThreadFactory = new ThreadFactory() {
        private final AtomicInteger mCount = new AtomicInteger(1);

        public Thread newThread(Runnable r) {
            return new Thread(r, "AsyncTask #" + mCount.getAndIncrement());
        }
    };

    private static final BlockingQueue<Runnable> sPoolWorkQueue =
            new LinkedBlockingQueue<Runnable>(128);

...}
private GoogleMap mMap;

JSONArray contentJson;

String contentId;
String imageJsonUrl;
String userId;
Bitmap bmp;
LatLng latLng;
Marker m;
HashMap<Marker, String> hashMap;

int k = 0;

// check value for Request check
final int MY_LOCATION_REQUEST_CODE = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(myToolbar);

    getSupportActionBar().setDisplayShowTitleEnabled(false);

    if(this.getIntent().getExtras() != null) {
            try {
                contentJson = new JSONArray(this.getIntent().getStringExtra("contentJson"));
               // Log.v("TESTITEST", contentJson.toString());
            } catch (JSONException e) {
                Log.e("EXCEPTION", "unexpected JSON exception", e);
                e.printStackTrace();
            }
    }
}

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_maps, menu);
    return true;
}

public LatLng getLatLngPosition() {
    return new LatLng(0, 0);
}

/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {

    mMap = googleMap;

    //Ask for Permission. If granted show my Location
    if (ActivityCompat.checkSelfPermission(MapsActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {
        // Check Permissions Now
        ActivityCompat.requestPermissions(MapsActivity.this,
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                MY_LOCATION_REQUEST_CODE);
    } else {
        // permission has been granted, continue as usual
        mMap.setMyLocationEnabled(true);
    }

    PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
            getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {

            // TODO: Get info about the selected place.
            LatLng selectedLocation = place.getLatLng();
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(selectedLocation, 10f));
        }

        @Override
        public void onError(Status status) {
            // TODO: Handle the error.
            Log.i("PlaceSelectorError", "An error occurred: " + status);
        }
    });

    LatLng bonn = new LatLng(50.7323, 7.1847);
    LatLng cologne = new LatLng(50.9333333, 6.95);
    //mMap.addMarker(new MarkerOptions().position(bonn).title("Marker in Bonn"));

    // hash map for saving content id with marker
    hashMap = new HashMap<Marker, String>();

    if(contentJson != null) {

        if (this.getIntent().getStringExtra("contentId") == null) {
            // show all contents of my friends
            try {
                for (int i = 0; i < contentJson.length(); i++) {
                    JSONObject jsonInfo = contentJson.getJSONObject(i);

                    JSONArray contents = jsonInfo.getJSONArray("content");
                    // Log.v("contentslength", String.valueOf(contents.length()));

                    //get all contents of one user
                    for (int j = 0; j < contents.length(); j++) {
                        JSONObject eachcontent = contents.getJSONObject(j);
                        //Log.v("eachcontent", eachcontent.toString());
                        JSONObject location = eachcontent.getJSONObject("Location");
                        String contentId = eachcontent.getString("id");
                        String contentTitle = eachcontent.getString("title");
                        userId = eachcontent.getString("user_id");
                        latLng = new LatLng(Double.valueOf(location.getString("latitude")), Double.valueOf(location.getString("longitude")));
                        new MapImageLoadTask("http://192.168.63.35:1234/rest_app_users/getImage/", userId, contentId, contentTitle, latLng).execute();


                        Log.v("contentTitle", contentTitle);
                        //Log.v("m", m.toString());
                        //m = mMap.addMarker(new MarkerOptions().title(contentTitle).position(new LatLng(Double.valueOf(location.getString("latitude")), Double.valueOf(location.getString("longitude")))).icon(BitmapDescriptorFactory.fromBitmap(bmp)));
                    }
                }
            } catch (JSONException e) {
                Log.e("Exception", "unexpected JSON exception", e);
                e.printStackTrace();
            }
        }


        else {
            // if we only want to see a specific content
            try {
                List<RequestData> datas = new ArrayList<RequestData>();
                for (int i = 0; i < contentJson.length(); i++) {
                    JSONObject jsonInfo = contentJson.getJSONObject(i);

                    JSONArray contents = jsonInfo.getJSONArray("content");

                    //get all contents of one user


                    for (int j = 0; j < contents.length(); j++) {
                        JSONObject eachcontent = contents.getJSONObject(j);
                        JSONObject location = eachcontent.getJSONObject("Location");
                        if(eachcontent.getString("id").equals(this.getIntent().getStringExtra("contentId"))) {

                            String contentId = eachcontent.getString("id");
                            String contentTitle = eachcontent.getString("title");
                            userId = eachcontent.getString("user_id");
                            latLng = new LatLng(Double.valueOf(location.getString("latitude")), Double.valueOf(location.getString("longitude")));
                          //  Log.v("LATLNG", contentId);


                              RequestData data = new RequestData();
                              data.url = "http://192.168.63.35:1234/rest_app_users/getImage/";
                              data.userId = userId;
                              data.contentId = contentId;
                              data.contentTitle = contentTitle;
                              data.latlng = latlng;
                              datas.add(data);
                            //new MapImageLoadTask("http://192.168.63.35:1234/rest_app_users/getImage/", userId, contentId, contentTitle, latLng).execute();

                            continue;

                        }
                    }
                }

                new MapImageLoadTask(datas).execute();

            } catch (JSONException e) {
                Log.e("LOGEDILOG", "unexpected JSON exception", e);
                e.printStackTrace();
            }
        }
    }

    mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
        @Override
        public void onMyLocationChange(Location location) {
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                    new LatLng(location.getLatitude(), location.getLongitude()), 10f));
            mMap.setOnMyLocationChangeListener(null);
        }
    });

    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {
            String id = hashMap.get(marker);
            Log.v("BITMAP", bmp.toString());
            try {
                Context context = getApplicationContext();
                Intent mapIntent = new Intent(getApplicationContext(), contentDetailActivity.class);
                mapIntent.putExtra("contentId", id);
                mapIntent.putExtra("contentJson", contentJson.toString());
                mapIntent.putExtra("userId", userId);
                String filename = "profileImage.png";
                FileOutputStream stream = context.openFileOutput(filename, Context.MODE_PRIVATE);
                bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);

                //Cleanup
                stream.close();
                mapIntent.putExtra("image", filename);

                startActivity(mapIntent);

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

public Marker[] addMarkers() {
    return null;
}

/**
 *  lets you load Image from external source via url
 */

static class RequestData{

   public String url;
   public String userId;
   public String contentId;
   public String contentTitle;
   public LatLng latLng;
   public Bitmap bmp;
}


public class MapImageLoadTask extends AsyncTask<Void, RequestData, Void> {
    private final String LOG_TAG = MapImageLoadTask.class.getSimpleName();
    BufferedReader reader = null;


   List<RequestData> dataSet;

    public MapImageLoadTask(List<RequestData> dataSet) {
        this.dataSet = dataSet;
    }

    private String getImageUrlFromJson(String imageJson) throws JSONException {

        JSONObject imageJsonOutput = new JSONObject(imageJson);
        imageJsonUrl = imageJsonOutput.getString("imageUrl");
        //Log.v(LOG_TAG, imageJsonUrl);
        return imageJsonUrl;
    }

    @Override
    protected Bitmap doInBackground(Void... params) {

        for(RequestData item : dataSet){
            String imageJson = null;
              try {
                  URL urlConnection = new URL(url + userId);
                  HttpURLConnection connection = (HttpURLConnection) urlConnection
                          .openConnection();
                  connection.setDoInput(true);
                  connection.connect();
                  InputStream input = connection.getInputStream();
                  StringBuffer buffer = new StringBuffer();
                  if (input == null) {
                      // Nothing to do.
                      //forecastJsonStr = null;
                      return null;
                  }

                  reader = new BufferedReader(new InputStreamReader(input));

                  String line;
                  while ((line = reader.readLine()) != null) {
                      // Since it's JSON, adding a newline isn't necessary (it won't affect parsing)
                      // But it does make debugging a *lot* easier if you print out the completed
                      // buffer for debugging.
                      buffer.append(line + "\n");
                  }

                  if (buffer.length() == 0) {
                      return null;
                  }

                  imageJson = buffer.toString();

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


              try {
                  String jsonUrl = getImageUrlFromJson(imageJson);
                  URL url = new URL(jsonUrl);
                  bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                  // 
                  item.bmp = bmp;
                  publishProgress(item);
              }
              catch(Exception e) {
                  e.printStackTrace();
              }

         }



        return null;
    }

    protected void onPublishProgress(RequestData item){
        k +=1;
        Log.v("COUNTER", String.valueOf(k));
        m = mMap.addMarker(new MarkerOptions().title(item.title).position(item.location).icon(BitmapDescriptorFactory.fromBitmap(item.bmp)));
        hashMap.put(m, contentId);
    }

    @Override
    protected void onPostExecute(Bitmap result) {
        super.onPostExecute(result);


    }
}
}