猿问

GeoCorder:无法在 getFromLocation() 中传递 LatLng

现在,我试图让一个地区的国家名字,但我无法通过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.Exception


getFromLocation() 不能应用于:纬度双位置。纬度经度双位置。经度


我有什么问题吗?


FFIVE
浏览 124回答 1
1回答

手掌心

只处理异常。要么扔掉它,要么抓住它。public void checkCountry(LatLng location) {&nbsp; &nbsp; Geocoder gcd = new Geocoder(this, Locale.getDefaut());&nbsp; &nbsp; List<Address> addresses=new ArrayList<>();&nbsp; &nbsp; try{&nbsp; &nbsp; &nbsp; &nbsp; addresses=&nbsp; gcd.getFromLocation(location.latitude, location.longitude, 1); //error here&nbsp; &nbsp; }catch (Exception e){&nbsp; &nbsp; &nbsp; &nbsp; e.printStackTrace();&nbsp; &nbsp; }&nbsp; &nbsp; String country;&nbsp; &nbsp; if(addresses!=null)if(addresses.size()!=0) country= addresses.get(0).getCountryName();}
随时随地看视频慕课网APP

相关分类

Java
我要回答