始终getLocationFromName返回null值

时间:2016-03-07 14:51:40

标签: android

gc.getLocationFromName()始终是returnig null值。列表是空的我无法找到解决方案。

public void geoLocate(View view) throws IOException {
    hideSoftKeyboard(view);
    EditText etValue=(EditText)findViewById(R.id.etValue);
    String location = etValue.getText().toString();

    Log.d("-----Location :" , location);

    Geocoder gc= new Geocoder(getBaseContext(), Locale.getDefault());
    List<Address> list=gc.getFromLocationName(location,1);
    int size=list.size();
    Log.d("Size---" ,""+size);
    if(list!=null && list.size()>0) {
        Address add = list.get(0);

        String locality = add.getLocality();
        Log.e("----Locality", locality);
        Toast.makeText(this, locality, Toast.LENGTH_LONG).show();
    }
    else
    {
        Toast.makeText(this, "NULL VALUE RETURNED", Toast.LENGTH_LONG).show();
    }

}

1 个答案:

答案 0 :(得分:0)

@Dharma

替换

List<Address> list=gc.getFromLocationName(location,1);

List<Address> list= new ArrayList<>();
list = gc.getFromLocationName(location,1);