【问题标题】:GeoCorder: Cannot pass LatLng in getFromLocation()GeoCoder:无法在 getFromLocation() 中传递 LatLng
【发布时间】:2018-10-05 09:18:48
【问题描述】:

现在我正在尝试获取位置的国家/地区名称,但我无法在 getFromLocation() 中传递 LatLng。 我该如何解决这个问题?

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() 不能应用于: 纬度双位置.纬度 longtitude double location.longtitude

我有什么问题?

【问题讨论】:

    标签: java android google-maps google-geocoder


    【解决方案1】:

    只处理异常。要么扔,要么接。

    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();
    }
    

    【讨论】:

      猜你喜欢
      • 2012-04-11
      • 2014-10-24
      • 2022-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多