1

如何在android中使用反向地理编码获得更准确的位置。我对此进行了很多搜索,但找不到所需的解决方案。有没有办法使用反向地理编码的高度和其他位置字段来获取位置?

编辑:

    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();
    }
}

这是我到目前为止所尝试的。

4

1 回答 1

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

于 2014-05-23T05:28:01.803 回答