现在,我试图让一个地区的国家名字,但我无法通过LatLng在getFromLocation()。我怎样才能解决这个问题?public void checkCountry(LatLng location) { Geocoder gcd = new Geocoder(this, Locale.getDefaut()); List<Address> addresses = gcd.getFromLocation(location.latitude, location.logtitude, 1); //error here String country = addresses.get(0).getCountryName();错误说未处理的异常:java.IO.ExceptiongetFromLocation() 不能应用于:纬度双位置。纬度经度双位置。经度我有什么问题吗?
1 回答
手掌心
TA贡献1942条经验 获得超3个赞
只处理异常。要么扔掉它,要么抓住它。
public void checkCountry(LatLng location) {
Geocoder gcd = new Geocoder(this, Locale.getDefaut());
List<Address> addresses=new ArrayList<>();
try{
addresses= gcd.getFromLocation(location.latitude, location.longitude, 1); //error here
}catch (Exception e){
e.printStackTrace();
}
String country;
if(addresses!=null)if(addresses.size()!=0) country= addresses.get(0).getCountryName();
}
添加回答
举报
0/150
提交
取消