2012-05-23 5 views

답변

0

Android 앱에지도를 표시하는 방법을 알고 계십니까? 그렇지 않다면 this 멋진 자습서를 살펴보십시오.

그런 다음 표시 주소는 다음과 같이 수행 할 수 있습니다 다음은 클릭의 좌표를 얻기 위해

Geocoder geocoder = new Geocoder(this, Locale.getDefault()); 
    List<Address> addresses = geocoder.getFromLocation(lat, lng, 1); 
0

,이 스레드 확인 :

Getting coordinates when clicking anywhere on a MapView

을 당신은 ADRESS로 좌표를 설정할 수 있습니다 이 :

Address a = ((Address)geocoder.getFromLocation(latiAsDouble, longiAsDouble, 1).get(0)); 
String Position = a.getAddressLine(1) + " - " + a.getAddressLine(0); 

이것은 httpc 모든 Google 서버에, 그래서 당신은 일종의 스레드에 넣을 수 있습니다.

6

발견 Google API는 역 지오 코딩에 매우 편리합니다. 이를 위해이 클래스를 만들었습니다. 앱에서이 클래스를 직접 사용할 수 있습니다.

public class getReverseGeoCoding 
{ 
    private String Address1 = "", Address2 = "", City = "", State = "", Country = "", County = "", PIN = ""; 

    public void getAddress() 
    { 
     Address1 = ""; Address2 = ""; City = ""; State = ""; Country = ""; County = ""; PIN = ""; 

     try { 

      JSONObject jsonObj = parser_Json.getJSONfromURL("http://maps.googleapis.com/maps/api/geocode/json?latlng="+ Global.curLatitude + "," + Global.curLongitude +"&sensor=true"); 
      String Status = jsonObj.getString("status"); 
      if(Status.equalsIgnoreCase("OK")) 
      { 
       JSONArray Results = jsonObj.getJSONArray("results"); 
       JSONObject zero = Results.getJSONObject(0); 
       JSONArray address_components = zero.getJSONArray("address_components"); 

       for(int i = 0; i<address_components.length(); i++) 
       { 
        JSONObject zero2 = address_components.getJSONObject(i); 
        String long_name = zero2.getString("long_name"); 
        JSONArray mtypes = zero2.getJSONArray("types"); 
        String Type = mtypes.getString(0); 

        if(TextUtils.isEmpty(long_name) == false || !long_name.equals(null) || long_name.length() > 0 || long_name != "") 
        { 
         if(Type.equalsIgnoreCase("street_number")) 
         { 
          Address1 = long_name + " "; 
         } 
         else if(Type.equalsIgnoreCase("route")) 
         { 
          Address1 = Address1 + long_name; 
         } 
         else if(Type.equalsIgnoreCase("sublocality")) 
         { 
          Address2 = long_name; 
         } 
         else if(Type.equalsIgnoreCase("locality")) 
         { 
//       Address2 = Address2 + long_name + ", "; 
          City = long_name; 
         } 
         else if(Type.equalsIgnoreCase("administrative_area_level_2")) 
         { 
          County = long_name; 
         } 
         else if(Type.equalsIgnoreCase("administrative_area_level_1")) 
         { 
          State = long_name; 
         } 
         else if(Type.equalsIgnoreCase("country")) 
         { 
          Country = long_name; 
         } 
         else if(Type.equalsIgnoreCase("postal_code")) 
         { 
          PIN = long_name; 
         } 
        } 

//     JSONArray mtypes = zero2.getJSONArray("types"); 
//     String Type = mtypes.getString(0); 
//     Log.e(Type,long_name); 
       } 
      } 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 


    } 

    public String getAddress1() 
    { 
     return Address1; 

    } 

    public String getAddress2() 
    { 
     return Address2; 

    } 

    public String getCity() 
    { 
     return City; 

    } 

    public String getState() 
    { 
     return State; 

    } 

    public String getCountry() 
    { 
     return Country; 

    } 

    public String getCounty() 
    { 
     return County; 

    } 

    public String getPIN() 
    { 
     return PIN; 

    }