我正在使用地理编码来转换地址中的纬度和经度值。这不是返回 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;
}