1

How can I get more accurate position with reverse geocoding in android.I have searched a lot on this,but could not find a desired solution.Is there any way using the altitude and other fields of location on reverse geocoding to get location?

Edit:

    Geocoder geocoder = new Geocoder(this, Locale.ENGLISH);

    try {

        List<Address> addresses = geocoder.getFromLocation(latitude,
                longitude, 5);
        address=new ArrayList<String>();
        log.debug(addresses.size());
        if (addresses != null&&addresses.size()>0) {

            Address fetchedAddress = addresses.get(0);

            for (int i = 0; i < fetchedAddress.getMaxAddressLineIndex(); i++) {
                address.add(fetchedAddress.getAddressLine(i));
            }

        }

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Toast.makeText(getApplicationContext(), "Could not get address..!",
                Toast.LENGTH_LONG).show();
    }
}

This is what I have tried so far.

KKGanguly
  • 323
  • 3
  • 13

1 Answers1

0

There is some time problem with inbuilt class of android geocoding... There are alternative ways are...

1.)you can get the result, this might get the the accurate result over the default geocoder class.

public static String getUserLocation(String lat, String lon) {
        String userlocation = null;
        String readUserFeed = readUserLocationFeed(lat.trim() + ","+ lon.trim());
        try {
            JSONObject Strjson = new JSONObject(readUserFeed);
            JSONArray jsonArray = new JSONArray(Strjson.getString("results"));
            userlocation = jsonArray.getJSONObject(1)
                    .getString("formatted_address").toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Log.i("User Location ", userlocation);
        return userlocation;
    }



      public static String readUserLocationFeed(String address) {
        StringBuilder builder = new StringBuilder();
        HttpClient client = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet("http://maps.google.com/maps/api/geocode/json?latlng="+ address + "&sensor=false");
        try {
            HttpResponse response = client.execute(httpGet);
            StatusLine statusLine = response.getStatusLine();
            int statusCode = statusLine.getStatusCode();
            if (statusCode == 200) {
                HttpEntity entity = response.getEntity();
                InputStream content = entity.getContent();
                BufferedReader reader = new BufferedReader(new InputStreamReader(content));
                String line;
                while ((line = reader.readLine()) != null) {
                    builder.append(line);
                }
            } else {
                Log.e(ReverseGeocode.class.toString(), "Failed to download file");
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return builder.toString();
    }

please go at-list once at the google json refrances google json out format

GovindRathod
  • 867
  • 1
  • 8
  • 22