2017-02-24 5 views
0

나는 다음과 같은 주소를 위도 LNG를 얻기 위해 노력하고 있지만, 지오 코더는 위도 LNG 찾을 수 없습니다 :지오 코더 (Geocoder)가 안드로이드의 특정 문자열에서 lat lng를 가져올 수 없습니까?

Cascina에 팔라의 n.9 -

이탈리아

10046 - 스트라 Provinciale 134, POIRINO (TO) 다음과 같이

내 코드는 다음과 같습니다

public static LatLng getLocationFromAddress(Context context, String strAddress) { 
    Geocoder coder = new Geocoder(context); 
    List<Address> address; 
    LatLng p1 = null; 
    try { 
     address = coder.getFromLocationName(strAddress, 5); 
     if (address == null) { 
      return null; 
     } 
     Address location = address.get(0); 
     location.getLatitude(); 
     location.getLongitude(); 
    p1 = new LatLng(location.getLatitude(), location.getLongitude()); 
    } catch (Exception ex) { 
     Timber.d("getLocationFromAddress(printStackTrace): " + ex); 
    } 
    return p1; 
} 

편집 1 : 또한

, 나는 settin으로 시도 g 지역 코더에서 이탈리아와 수동으로 로케일을하지만 여전히 결과를 얻을 수 없습니다.

+1

그래는 REST API를 작업처럼 보이는하지만 왜 안드로이드에 모른다. http://maps.google.com/maps/api/geocode/json?address=Cascina%20Palazzetto%20n.9%20-%20Strada%20Provinciale%20134,%20POIRINO%20(TO)%20-% 2010046, % 20Italia & sensor = false –

+0

로그를 제공 할 수 있습니까? – Cottontree

+0

List 개체 주소는 로그에서 정보를 얻을 수없는 대신 크기가 0입니다. –

답변

0

주소 목록에 대한 루프를 실행하고 lat, long break loop를 얻으려고합니다.

처럼,

public static LatLng getLocationFromAddress(Context context, String strAddress) { 
     Geocoder coder = new Geocoder(context); 
     List<Address> address; 
     LatLng p1 = null; 
     try { 
      address = coder.getFromLocationName(strAddress, 5); 
      if (address == null) { 
       return null; 
      } 

      for(int i=0;i<address.size();i++) 
      { 


      Address location = address.get(i); 

      if(location.getLatitide!=0 && location.getLongitude!=0) 
      { 
         location.getLatitude(); 
         location.getLongitude(); 
         p1 = new LatLng(location.getLatitude(),      location.getLongitude()); 

        break; 
      } 
     } 
     } catch (Exception ex) { 
      Timber.d("getLocationFromAddress(printStackTrace): " + ex); 
     } 
     return p1; 
    } 
+0

하지만 배열 크기가 0이므로 시나리오가 동일합니다. –

+0

크기를 10으로 만들고 try => address = coder.getFromLocationName (strAddress, 10); – Ragini

+0

같은 결과 .... –