Android中的Geo编码器后端服务实现

时间:2013-02-09 13:03:06

标签: android android-intent

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

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;
}

1 个答案:

答案 0 :(得分:-1)

  

public static boolean isPresent()

     

如果Geocoder方法为getFromLocation,则返回true   getFromLocationName已实现。 可能缺乏网络连接   仍会导致这些方法返回null或空列表。