Hello. this is my code of MapsActivity.java, and I don't see my markers 
from mysql database. The error in logcat is:

Value 
[{"LAT":"41.1172905","LON":"16.4837252"},{"LAT":"41.1171432","LON":"16.8718715"},{"LAT":"40.8476509","LON":"15.5404692"},{"LAT":"48.856614","LON":"2.3522219"},{"LAT":"40.8517746","LON":"14.2681244"}]
 
of type org.json.JSONArray cannot be converted to JSONObject

The error shows the json result of my php code. This php page is the url 
string passed to get coordinates and markers.

Please help me. Nice thanks

This the java code:

public class MapsActivity extends FragmentActivity implements 
OnMapReadyCallback {

    private GoogleMap mMap;
    private Double Latitude = 0.00;
    private Double Longitude = 0.00;

    @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);

        new JSONTask().execute("http://192.168.1.101/crud/markers_android.php";);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

    }

        public class JSONTask extends AsyncTask<String, String, String> {

            @Override
            protected String doInBackground(String... params) {
                HttpURLConnection connection = null;
                BufferedReader reader = null;

                try {
                    URL url = new URL(params[0]);
                    connection = (HttpURLConnection) url.openConnection();
                    connection.connect();

                    InputStream stream = connection.getInputStream();
                    reader = new BufferedReader(new InputStreamReader(stream));

                    StringBuffer buffer = new StringBuffer();
                    String line = "";
                    while ((line = reader.readLine()) != null) {
                        buffer.append(line);
                    }

                    String finalJson = buffer.toString();
                    JSONObject parentObject = new JSONObject(finalJson);
                    JSONArray parentArray = new JSONArray();

                    //;
                    //JSONArray parentArray = parentObject.getJSONArray("");

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

                        JSONObject finalObject = parentArray.getJSONObject(i);
                        String lat = finalObject.getString("LAT");
                        Latitude = Double.parseDouble(lat.toString());
                        String lon = finalObject.getString("LON");
                        Longitude = Double.parseDouble(lon.toString());
                        Log.w("eeee", "Lat : " + lat + "  Lon : " + lon);

                        MarkerOptions marker = new MarkerOptions().position(new 
LatLng(Latitude, Longitude));
                        mMap.addMarker(marker);
                    }

                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    e.printStackTrace();
                } finally {
                    if (connection != null) {
                        connection.disconnect();
                    }
                    try {
                        if (reader != null) {
                            reader.close();
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                return null;
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);

            }
        }
    }


Code php is here <http://pastebin.com/HEKxBCRd>

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/21d13630-d4bb-42e4-8b09-89924286449d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to