Pergunta

I have an android map which is supposed to display markers parsed form JSON. My loop is working and parsing the JSON, but its only parsing it for the first six items, then it is stopping and either stopping to parse or not displaying the markers on my google maps.

My JSON request is returning this JSON:

https://gist.github.com/anonymous/02e2b88c4de8ac2fe732

(Linked it so I did not fill all the characters for this question)

And my async task which is parsing the JSON and adding the markers to my map is:

protected void onPostExecute(String result){
        //decode json here
        try{
            JSONArray jsonArray = new JSONArray(result);

            LatLngBounds.Builder b = new LatLngBounds.Builder();


            for(int i = 0; i < jsonArray.length(); i++) {

                String breweryName = jsonArray.getJSONObject(i).getString("brewery");
                String lat = jsonArray.getJSONObject(i).getString("lat");
                String lng = jsonArray.getJSONObject(i).getString("lng");
                String bID = jsonArray.getJSONObject(i).getString("breweryID");

                double latD = Double.parseDouble(lat);
                double lngD = Double.parseDouble(lng);



                m.addMarker(new MarkerOptions()
                        .position(new LatLng(latD, lngD))
                        .title(breweryName));

                b.include(new LatLng(latD, lngD));


            }

            LatLngBounds bounds = b.build();
            //Change the padding as per needed
            CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 25, 25, 5);
            m.animateCamera(cu);





        }
        catch(Exception e){

        }

        Dialog.dismiss();

    }

UPDATE:

I know for a fact its probably messing up with one of the names or values in my JSON. Either adding the marker or something. Basically its breaking the loop and stopping the rest of the async task. I placed a toast after the loop and its not getting to it.

Foi útil?

Solução

The input is incorrect. This record

{
    "brewery": "Ayinger Brewery",
    "lat": "",
    "lng": "",
    "breweryID": "QKdFk2"
},

is missing lat and lng values, which causes Double.parseDouble() to fail.

Printing the exception's stack trace in the catch would've been helpful to debug it.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top