2014-05-23 71 views
1

如何在android.I中使用反向地理编码获得更准确的位置我在这方面搜索了很多,但找不到所需的解决方案。是否有任何方法使用海拔高度和其他位置的反向位置地理编码获取位置?获取更准确的位置

编辑:

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

亚去一次。这是可能的,但告诉我你到现在为止尝试过什么? –

+1

你试过用google json WS吗? –

+0

不,我试过geocoder – KKGanguly

回答

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

请在列表在谷歌JSON refrances google json out format