0

I am following a tutorial to parse JSON objects. The tutorial defines:

  ArrayList<HashMap<String, String>> contactList;

and later it is adding each JSON object to the ArrayList:

                        // tmp hashmap for single contact
                        HashMap<String, String> contact = new HashMap<String, String>();

                        // adding each child node to HashMap key => value
                        contact.put(TAG_IDOBJETO, idObjeto);
                        contact.put(TAG_TITULO, titulo);
                        contact.put(TAG_DIRECCION, direccion);
                        contact.put(TAG_LATITUD, latitud);
                        contact.put(TAG_LONGITUD, longitud);
                        contact.put(TAG_PROCEDENCIA, procedencia);
                        contact.put(TAG_IMAGEN, imagen);
                        Log.e("REGISTRO ACTUAL",procedencia);
                        // adding contact to contact list
                        contactList.add(contact);

I would now get the content of each object to create map makers, but I don't know how to do it. I need your help.

1 Answer 1

1

You just reverse the process:

int i = ...;
HashMap<String,String> contact = contactList.get(i); // get the i-th contact
String idObjecto = contact.get(TAG_IDOBJECTO);
// etc.

To iterate through the results in onPostExecute and create the markers:

protected void onPostExecute(...) {
    for (HashMap<String,String> contact : contactList) {
        Marker marker = map.addMarker(new MarkerOptions()
             .title(contact.get(TAG_TITULO))
             .position(new LatLng(
                 Double.parseDouble(contact.get(TAG_LATITUD)),
                 Double.parseDouble(contact.get(TAG_LONGITUD))
             ))
             // etc.
        );
        // do something with the marker
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for yor answer. Would you mind helping me creating the needed iteration at the onPostExecute method from the JSON parsing process to get all objects data to create the markers?
I really appreciate it, you have made my day, I have been looking for this for all the day long. Thank you very very much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.