Android..error同时查找给定位置的地址

时间:2017-12-07 13:29:04

标签: android

我是一个Android初学者收到错误:无法解析符号isPresent,在我的下面的代码片段中。专家,请帮忙!

Geocoder geo = new Geocoder(getApplicationContext(), Locale.getDefault());
    if(Geocoder.isPresent()){
        try {
            List<Address> addresses = geo.getFromLocation(l.getLatitude(),l.getLongitude(),1);
            if (addresses != null && addresses.size() >0){
                Address address = addresses.get(0);
                String addressText = String.format("%s,%s,%s", address.getLocality(),address.getCountryName());
                TextView place =(TextView)findViewById(R.id.place);
                place.setText(addressText);
            }

        }
        catch(IOException e){
            e.printStackTrace();
        }

2 个答案:

答案 0 :(得分:1)

请更改

if(Geocoder.isPresent()){
  //code here
 }

替换为

  if(geo.isPresent()){
   //code here
  }

答案 1 :(得分:0)

嗯,问题解决了。发生错误是因为片段出现在一组代码之后,这些代码在onCreate方法之外。因此初学者造成浪费时间。

相关问题