我有一个大问题。
我编写了这段代码来获取与坐标相关的地址信息:
public static Address getAddressFromLocation(Context c, Location location){
Address address = null;
if(location!=null){
final Double addrLat=location.getLatitude();
final Double addrLng=location.getLongitude();
final Geocoder geocoder = new Geocoder(c, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(getRound(addrLat, 15), getRound(addrLng, 15), 1);
if (addresses.size() > 0) {
Address returnedAddress = addresses.get(0);
Locale locale = returnedAddress.getLocale();
address = new Address(locale);
address = returnedAddress;
if(address.getLocality()==null || address.getLocality().equals("")){
int line = address.getMaxAddressLineIndex()-1;
if(line<0)line=0;
address.setLocality(address.getAddressLine(line));
}
}else{
address=null;
}
}catch (IOException e) {
address=null;
}
}else{
address=null;
}
return address;
}
多次执行搜索后,我没有得到地址,我不明白为什么。
我可以在一段时间后重新启动设备或进行搜索,但我再也找不到任何地址了。
错误是:
java.io.IOException: Service not Available
哪个是问题?