0

I think i write wrong my code where i try to retrieve geolocation data: All relevant api keys are added and relevant api enabled...

private class GetCoordinates extends AsyncTask<String, Void, String>
    {
        ProgressDialog dialog = new ProgressDialog(AroundMeMapsActivity.this);

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            dialog.setMessage("Please wait...");
            dialog.setCanceledOnTouchOutside(true);
            dialog.show();
        }

        @Override
        protected String doInBackground(String... strings) {
            String response;
            try {
                Toast.makeText(AroundMeMapsActivity.this, "!!!!", Toast.LENGTH_SHORT).show();

                String address = strings[0];
                HttpDataHandler http = new HttpDataHandler();
                //String url = String.format("https://maps.googleapis.com/maps/api/geocode/json?adress=%s", address);
                String url = String.format("https://maps.googleapis.com/maps/api/geocode/json?address=%s&key=AIzaSyAzSgqQEZS1K1fowxhUnwxl4hMsKMsLlN4", address);
                response = http.getHTTPData(url);
                return response;
            } catch (Exception ex) {

            }
            return null;
        }

        @Override
        protected void onPostExecute(String s) {
            try {
                Toast.makeText(AroundMeMapsActivity.this, "????", Toast.LENGTH_SHORT).show();
                JSONObject jsonObject=new JSONObject(s);

                String lat=((JSONArray)jsonObject.get("results")).getJSONObject(0).getJSONObject("geometry")
                        .getJSONObject("location").get("lat").toString();

                String lng=((JSONArray)jsonObject.get("results")).getJSONObject(0).getJSONObject("geometry")
                        .getJSONObject("location").get("lng").toString();

                answer_location.setText(String.format("Coordinates: %s / %s",lat,lng));
                if(dialog.isShowing())
                    dialog.dismiss();

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

I should get lat and lng coordinate, but it is not displayed...

Could you help to check why?

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
Dima Bokov
  • 91
  • 1
  • 14
  • better use the [client](https://github.com/googlemaps/google-maps-services-java) (it's generally server-side, the key needs to be restricted by key fingerprints). – Martin Zeitler Sep 01 '19 at 11:38
  • You may have to post your HttpDataHandler implementation - there are different implementations for http vs https (i.e. HttpsUrlConnection) which can't be verified in your post - see this post to start https://stackoverflow.com/a/36259778/2711811 - add logging for error paths (like the Exception block in `doInBackground`) –  Sep 01 '19 at 17:34

0 Answers0