0

我正在使用地理编码来转换地址中的纬度和经度值。这不是返回 true 到 is present()。如何使地理编码器可行?我需要为地理编码器实施支持服务吗?如果是,如何?

public String convert_address(){    
String address=" :: predefine address ::";

    try{
      Geocoder geocoder1;

    latitude = location.getLatitude();

    longitude = location.getLongitude();

    List<Address> addresses;

    geocoder1 = new Geocoder(mContext, Locale.getDefault());
    address=" geo enter";


     addresses = geocoder1.getFromLocation(latitude, longitude, 2);
     if(geocoder1.isPresent()==true)
         //Toast.makeText(getApplicationContext(), "it is present....", 500).show();
     address="...... present......";
         else
         //Toast.makeText(getApplicationContext(),"it is not....",500).show();
    address="....not present....";
     if(addresses != null) {
         Address returnedAddress = addresses.get(0);
         StringBuilder strReturnedAddress = new StringBuilder("Address:\n");
         for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
         strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
         }
         address=strReturnedAddress.toString();
         }
         else{
         address="No Address returned!";
         }



    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    return address;
}
4

1 回答 1

-1

公共静态布尔isPresent()

如果实现了地理编码器方法 getFromLocation 和 getFromLocationName,则返回 true。缺乏网络连接仍可能导致这些方法返回 null 或空列表。

于 2013-02-13T09:51:58.923 回答