为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

FFIVE 2021-10-28 14:05:49
现在,我试图让一个地区的国家名字,但我无法通过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();

}


查看完整回答
反对 回复 2021-10-28
  • 1 回答
  • 0 关注
  • 123 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信