0

for some reason this JSON request is not going through, I checked that I have internet connection and that everything is fine. It used to work perfectly, I am not sure what happened, I did touch the code since it started working. When I don't have a connection it throws an error. All logs inside don't post. I am really not sure what happened. Can anyone please help me. It's like it skips over the entire request for some reason. Thank you.

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest("https://maps.google.com/maps/api/geocode/json?latlng=" + latitude + "," + longitude + "&key=AIzaSyDoj_f_2-gGLy5ClzVQwmtscMy9dW2KoNI",
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject jsonObject) {

                    String addre = null;
                    Address addr1 = null;

                    String address1 = "", address2 = "", city = "", state = "", country = "", county = "", pin = "";

                    try {
                        addre = ((JSONArray) jsonObject.get("results")).getJSONObject(0).getString("formatted_address");

                        if ("OK".equalsIgnoreCase(jsonObject.getString("status"))) {


//                                JSONArray Results = jsonObject.getJSONArray("results");
//                                JSONObject zero = Results.getJSONObject(0);
                            Log.d("formated address ", "`" + addre);

                            String[] address = addre.split(",");

                            for (int i = 0; i < address.length; i++) {
                                Log.d("address " + i, "`" + address[i]);
                            }


                            city = address[1];
                            state = address[2].split(" ")[1];
                            country = address[3];


                            Log.d("addr_label", "`" + addre);
                            Log.d("city", "`" + city);
                            Log.d("state", "`" + state);
                            Log.d("country", "`" + country);


                        }
                        if (country.trim().equals("USA")) {
                            if (city == null && state == null) {
                                locationView.setText("No Location Found");
                            } else if (state == null) {
                                locationView.setText(city);
                            } else if (city == null) {
                                locationView.setText(state);
                            }
                            locationView.setText(city + ", \n" + state);
                        } else {
                            if (country == null && state == null) {
                                locationView.setText("No Location Found");
                            } else if (state == null) {
                                locationView.setText(country);
                            } else if (country == null) {
                                locationView.setText(state);
                            }
                            locationView.setText(state + ", \n" + country);
                        }

                        if (locationView.getText().toString().trim().isEmpty()) {
                            locationView.setText("No Location Found");
                        }

                        Log.d("Location View", "`" + locationView.getText());


                    } catch (JSONException e) {
                        e.printStackTrace();
                        Log.d("Location", "catch");
                        locationView.setText("No Location Found");
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {
        }
    });
    requestQueue.add(jsonObjectRequest);

Thanks Again.

Edon Freiner
  • 338
  • 2
  • 17
  • What are you using to connect to api, volley? – Vihanga Yasith Dec 01 '17 at 17:04
  • can you show logs – Bek Dec 01 '17 at 17:12
  • Your code seems to be working fine. Only problem can be with your longitude and latitudes. Hard-code the url. try [this](https://maps.google.com/maps/api/geocode/json?latlng=6.911334346,79.8809143&key=AIzaSyDoj_f_2-gGLy5ClzVQwmtscMy9dW2KoNI) – Vihanga Yasith Dec 01 '17 at 17:13
  • Your log probably pointing on place where exception is throw – Yupi Dec 01 '17 at 17:26
  • @VihangaYasith I am not sure, I am kind of new to this, I assume Volley, just because it says: `(VolleyError volleyError)` but I can't say for certain. I will try to hardcode my lat and long and get back to you. – Edon Freiner Dec 01 '17 at 19:01
  • @Bek There are no Logs that are being shown for this, that is the issue. – Edon Freiner Dec 01 '17 at 19:03
  • @Yupi there are no exceptions thrown. – Edon Freiner Dec 01 '17 at 19:04
  • then put a log inside onResponse on top to check if it is executed – Bek Dec 01 '17 at 19:06
  • I just hard coded the Lat and Long, and it still does not work. – Edon Freiner Dec 01 '17 at 19:07
  • @Bek there are multiple Logs in there and they do not get executed. – Edon Freiner Dec 01 '17 at 19:23
  • try to put log above `String addre = null; Address addr1 = null;` and inside `onErrorResponse` – Bek Dec 01 '17 at 19:28
  • I printed the stack trace from the onError and go this: `04-12 14:49:04.509 7562-7562/com.example.edonfreiner.siddur W/System.err: com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException: Could not validate certificate: current time: Thu Apr 12 14:49:01 EST 2018, expiration time: Thu Feb 08 01:00:00 EST 2018 ` I assume that means that I have a temporary certificate, how do I get a permanent one? And yes, the date APril 12, 2018 is the correct date that I am testing. – Edon Freiner Dec 01 '17 at 19:51
  • check this [answer](https://stackoverflow.com/a/32355818/4528663) – Vihanga Yasith Dec 01 '17 at 22:58
  • @VihangaYasith What does this have to do with this? – Edon Freiner Dec 02 '17 at 23:57

0 Answers0