Android - Geocoder并不全面

时间:2017-08-19 15:16:15

标签: android

我使用地理编码器从纬度和经度获取地址但我得到的JSON并不是非常全面,例如,我只获得了小巷和城市,但我无法获得街道名称或区域名称。必须有其他方法来实现这样的东西,但更全面。这是我的代码:

Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(context, Locale.getDefault());

try {
   addresses = geocoder.getFromLocation(currentLatLng.latitude, currentLatLng.longitude, 1);
   String text = addresses.get(0).getThoroughfare();
} catch (IOException e) {
   e.printStackTrace();
}

2 个答案:

答案 0 :(得分:1)

试试这个:

addresses = geocoder.getFromLocation(Latitude, Longitude,1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5
        String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
        String address1 = addresses.get(0).getAddressLine(1); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
        String address2 = addresses.get(0).getAddressLine(2); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
        String address3 = addresses.get(0).getAddressLine(3); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()

答案 1 :(得分:1)

您是否考虑过将Geocoding web service作为替代方案?

示例:

<html>                                                    
  <body>                                                  
  <div id="posts">
    <p>.Title</p>
    <p>.Body</p>                                        
    {{define "replies"}}                                  
    <ul>                                                  
      {{ range $key, $value := .Replies }}               
        <p>$value.Title</p>                               
        <p>$value.Body</p>                                
        <p>$.Random</p>                                   
        {{template "replies" . }}                         
        </li>                                             
      {{end}}                                             
    </ul>                                                 
    {{end}}                                               

  <div id="posts">                                        
    <div class="replyPost">{{ template "replies" .}}</div>
  </div>                                                  
  </body>                                                 
</html>