我正在使用下面的代码并在地址中获取空值。代码如下:-
Geocoder geocoder;
List<Address> addresses;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
geocoder = new Geocoder(this, Locale.getDefault());
try {
addresses = geocoder.getFromLocation(28.5202154,77.2006815, 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String address = addresses.get(0).getAddressLine(0);
String city = addresses.get(0).getAddressLine(1);
String country = addresses.get(0).getAddressLine(2);
Toast.makeText(
MainActivity.this,""+address+" "+city+" "+country, Toast.LENGTH_LONG).show();
}
当我调试代码时,它会给出一个在 catch 块中捕获的异常是服务不可用,当我在其他设备上运行相同的代码时,它会正常执行并根据需要提供完整的地址。伙计们请尝试解决这个问题。在此先感谢!