大きな問題があります。
座標に関連する住所情報を取得する次のコードを作成しました。
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
問題はどれですか?