0

Im trying to retrieve the address of a place using the google apis, where Im trying to use the api call by sending the geocodes. I tried changing the type of request from get to post but nothing works. But its giving an error :

Code :

 protected Void doInBackground(Location... params) {

            try {
                Location location = params[0];
                String finalURL = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + location.getLatitude() + ", " + location.getLongitude() + "&key=************************************";
                URL url = new URL(finalURL);
                HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                urlConnection.setRequestMethod("GET");
                urlConnection.connect();

                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
                String result = bufferedReader.readLine();
                JSONObject jo1 = new JSONObject(result);
                JSONArray jArray1 = jo1.getJSONArray("results");
                JSONObject jo2 = jArray1.getJSONObject(0);
                JSONArray jArray2 = jo2.getJSONArray("address_components");
                Log.d("address : ",jo2.getString("formatted_address"));


            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (ProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

The Error :

    Reconstruct Branch: AU_LINUX_ANDROID_LA.BF.1.1.04.04.02.162.107 + cb93e16 + f50fe49 + d7c18e6 + 5b9a565 + 0f3a25d + 607156e + 75511aa + e4d16c0 + 686f3eb + 211a271 + dd281ee +  NOTHING
06-30 13:29:12.207  27343-27441/com.example.kritarthaghosh.business_from_db I/OpenGLRenderer﹕ Initialized EGL, version 1.4
06-30 13:29:12.230  27343-27441/com.example.kritarthaghosh.business_from_db D/OpenGLRenderer﹕ Enabling debug mode 0
06-30 13:29:14.338  27343-27359/com.example.kritarthaghosh.business_from_db I/art﹕ Background sticky concurrent mark sweep GC freed 55471(2MB) AllocSpace objects, 49(3MB) LOS objects, 24% free, 13MB/18MB, paused 13.187ms total 69.368ms
06-30 13:29:21.413  27343-27679/com.example.kritarthaghosh.business_from_db W/System.err﹕ java.io.FileNotFoundException: https://maps.googleapis.com/maps/api/geocode/json?latlng=12.9592602, 77.7028222&key=************************************
06-30 13:29:21.426  27343-27679/com.example.kritarthaghosh.business_from_db W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:197)
06-30 13:29:21.426  27343-27679/com.example.kritarthaghosh.business_from_db W/System.err﹕ at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
06-30 13:29:21.426  27343-27679/com.example.kritarthaghosh.business_from_db W/System.err﹕ at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25)
06-30 13:29:21.427  27343-27679/com.example.kritarthaghosh.business_from_db W/System.err﹕ at com.example.kritarthaghosh.business_from_db.Opening_Screen$GetUserLocationDetails.doInBackground(Opening_Screen.java:117)
06-30 13:29:21.427  27343-27679/com.example.kritarthaghosh.business_from_db W/System.err﹕ at com.example.kritarthaghosh.business_from_db.Opening_Screen$GetUserLocationDetails.doInBackground(Opening_Screen.java:94)
06-30 13:29:21.427  27343-27679/com.example.kritarthaghosh.business_from_db W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
06-30 13:29:21.427  27343-27679/com.example.kritarthaghosh.business_from_db W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
06-30 13:29:21.427  27343-27679/com.example.kritarthaghosh.business_from_db W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
06-30 13:29:21.427  27343-27679/com.example.kritarthaghosh.business_from_db W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
06-30 13:29:21.427  27343-27679/com.example.kritarthaghosh.business_from_db W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
06-30 13:29:21.427  27343-27679/com.example.kritarthaghosh.business_from_db W/System.err﹕ at java.lang.Thread.run(Thread.java:818)

EDIT 2: ERROR

    Reconstruct Branch: AU_LINUX_ANDROID_LA.BF.1.1.04.04.02.162.107 + cb93e16 + f50fe49 + d7c18e6 + 5b9a565 + 0f3a25d + 607156e + 75511aa + e4d16c0 + 686f3eb + 211a271 + dd281ee +  NOTHING
06-30 13:45:12.191    1868-2002/com.example.kritarthaghosh.business_from_db I/OpenGLRenderer﹕ Initialized EGL, version 1.4
06-30 13:45:12.246    1868-2002/com.example.kritarthaghosh.business_from_db D/OpenGLRenderer﹕ Enabling debug mode 0
06-30 13:45:15.252    1868-2026/com.example.kritarthaghosh.business_from_db W/System.err﹕ org.json.JSONException: End of input at character 1 of {
06-30 13:45:15.279    1868-2026/com.example.kritarthaghosh.business_from_db W/System.err﹕ at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
06-30 13:45:15.279    1868-2026/com.example.kritarthaghosh.business_from_db W/System.err﹕ at org.json.JSONTokener.nextValue(JSONTokener.java:97)
06-30 13:45:15.279    1868-2026/com.example.kritarthaghosh.business_from_db W/System.err﹕ at org.json.JSONTokener.readObject(JSONTokener.java:362)
06-30 13:45:15.279    1868-2026/com.example.kritarthaghosh.business_from_db W/System.err﹕ at org.json.JSONTokener.nextValue(JSONTokener.java:100)
06-30 13:45:15.279    1868-2026/com.example.kritarthaghosh.business_from_db W/System.err﹕ at org.json.JSONObject.<init>(JSONObject.java:156)
06-30 13:45:15.279    1868-2026/com.example.kritarthaghosh.business_from_db W/System.err﹕ at org.json.JSONObject.<init>(JSONObject.java:173)
06-30 13:45:15.279    1868-2026/com.example.kritarthaghosh.business_from_db W/System.err﹕ at com.example.kritarthaghosh.business_from_db.Opening_Screen$GetUserLocationDetails.doInBackground(Opening_Screen.java:119)
06-30 13:45:15.279    1868-2026/com.example.kritarthaghosh.business_from_db W/System.err﹕ at com.example.kritarthaghosh.business_from_db.Opening_Screen$GetUserLocationDetails.doInBackground(Opening_Screen.java:94)
06-30 13:45:15.279    1868-2026/com.example.kritarthaghosh.business_from_db W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
06-30 13:45:15.279    1868-2026/com.example.kritarthaghosh.business_from_db W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
06-30 13:45:15.279    1868-2026/com.example.kritarthaghosh.business_from_db W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
06-30 13:45:15.279    1868-2026/com.example.kritarthaghosh.business_from_db W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
06-30 13:45:15.279    1868-2026/com.example.kritarthaghosh.business_from_db W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
06-30 13:45:15.279    1868-2026/com.example.kritarthaghosh.business_from_db W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
KrithGhosh
  • 88
  • 1
  • 5
  • 1
    Have you tried searching on here? I'm guessing it has to do with the spaces that you include in the URL as mentioned in a previous answer on this site. Therefore I do not post as an answer. You can look there http://stackoverflow.com/questions/23430032/issue-streaming-directions-for-google-maps-api-v2-android. Hope it helps – LBes Jun 30 '15 at 08:11
  • Don't edit this post, it's an other error that you're facing now so that your title doesn't match the error you're giving here. Create an other post. Also, feel free to upvote answers that helped you – LBes Jun 30 '15 at 08:19

0 Answers0