服务不可用时,我尝试在android系统从地理codeR得到的地址? [英] Service not available when I try to get address from Geocoder in android?
问题描述
有时我IOException异常,当我尝试过通过地理codeR类机器人的经度和纬度来获取地址。
这很少发生,并强制关闭我的申请。
私人无效locAdd(双纬度,经度双){
地理codeR地理codeR =新的地缘codeR(ReportActivity.this,
Locale.getDefault());
尝试{
清单<地址>地址=地理coder.getFromLocation(纬度,
经度,1);
Log.e(地址, - >中+地址);
}赶上(IOException异常五){
e.printStackTrace();
}
}
这是code我用得到的位置。是否存在与code的任何问题?
我该如何解决呢?
logcat的
java.io.IOException异常:无法解析来自服务器的响应
在android.location.Geo coder.getFromLocation(GEO coder.java:136)
在com.pstpl.crimeverify.CrimeReportActivity.locAdd(CrimeReportActivity.java:554)
在com.pstpl.crimeverify.CrimeReportActivity.access $ 10美元(CrimeReportActivity.java:549)
API文档,
<一个href=\"http://developer.android.com/reference/android/location/Geo$c$cr.html#getFromLocation%28double,%20double,%20int%29\" rel=\"nofollow\">http://developer.android.com/reference/android/location/Geo$c$cr.html#getFromLocation%28double,%20double,%20int%29
说,IOException异常将发生如果网络不可用或发生任何I / O问题。
我不认为这是与code的任何问题,因为它为有时。
顺便说一句,你是路过latitude1和经度的方法参数,但使用的是经度和纬度。
Sometimes I get the IOException when I try to get address through latitude and longitude via the geocoder class of android.
This occurs rarely and force closes my application.
private void locAdd(double latitude, double longitude) {
Geocoder geocoder = new Geocoder(ReportActivity.this,
Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(latitude,
longitude, 1);
Log.e("Addresses", "-->" + addresses);
} catch (IOException e) {
e.printStackTrace();
}
}
This is the code I use to get location. Is there any issue with the code? How do I solve it?
Logcat
java.io.IOException: Unable to parse response from server
at android.location.Geocoder.getFromLocation(Geocoder.java:136)
at com.pstpl.crimeverify.CrimeReportActivity.locAdd(CrimeReportActivity.java:554)
at com.pstpl.crimeverify.CrimeReportActivity.access$10(CrimeReportActivity.java:549)
The API documentation,
says that IOException will occur "if the network is unavailable or any other I/O problem occurs".
I don't think there is any problem with the code, since it works for "sometimes".
BTW, you are passing latitude1 and longitude as method arguments, but you are using latitude and longitude.
这篇关于服务不可用时,我尝试在android系统从地理codeR得到的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!