获得更准确的位置

时间:2014-05-23 04:50:45

标签: android location geocoding altitude

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

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

1 个答案:

答案 0 :(得分:0)

内置的android地理编码类存在一些时间问题... 还有其他方法......

1.)您可以获得结果,这可能会获得超过默认地理编码器类的准确结果。

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

请在google json refrances google json out format

进行一次列表