2017-11-08 12 views
0

위도를 사람이 읽을 수있는 주소로 변환하는 코드는 다음과 같습니다. 이제는 주소, 도시, 우편 번호 &을 포함하여 주소의 전체 세부 정보를 가져 오는 시간이 있는데 "인도"와 같은 카운티 이름 만 있습니다. 경도 & 위도를 기반으로 정확한 주소를 얻으려면 어떻게해야합니까? 도와주세요.위도, 경도로 지오 코딩 된 주소를 가져 오는 방법은 무엇입니까?

Geocoder 객체에서
final List<Address> list = gCoder.getFromLocation(locationLatitude, locationLongitude, 1); 
     if (list != null && list.size() > 0) { 
      Address address = list.get(0); 
      StringBuilder sb = new StringBuilder(); 

      if (address.getMaxAddressLineIndex() > 0) { 
       for (int i = 0; i < address.getMaxAddressLineIndex(); i++) { 
        sb.append(address.getAddressLine(i)).append(","); 
       } 
       sb.append(address.getCountryName()); 
      } else { 
       try { 
        sb.append(address.getAddressLine(0)); 
       } catch (Exception ignored) { 
       } 
      } 

      strAddress = sb.toString(); 
      strAddress = strAddress.replace(" ", ""); 
      strAddress = strAddress.replace(",null", ""); 
      strAddress = strAddress.replace("null", ""); 
      strAddress = strAddress.replace("Unnamed", ""); 
     } 
     getActivity().runOnUiThread(new Runnable() { 
      @Override 
      public void run() { 
       if (!TextUtils.isEmpty(strAddress)) { 
        tvLocation.setText(strAddress); 
        Log.e("Location", strAddress + ""); 
       }else { 
        Snackbar.make(getView(), "Couldn't get the location. Make sure location is enabled on the device", Snackbar.LENGTH_SHORT) 
          .show(); 
       } 
      } 
     }); 
+0

여기에서 확인할 수 있습니다. https://stackoverflow.com/a/9409229/5580210 –

답변

0

, 당신은 getFromLocation(double, double, int) 메서드를 호출 할 수 있습니다.

Geocoder gcd = new Geocoder(context, Locale.getDefault()); 
    List<Address> addresses = gcd.getFromLocation(lat, lng, 1); 
    if (addresses.size() > 0) { 
     System.out.println(addresses.get(0).getLocality()); 
    } 
    else { 
     // do your stuff 
    } 
+0

위치가 부정확합니다. – Gopal909