2016-03-07 105 views
0

gc.getLocationFromName()始終爲returnig空值。清單是空的,我無法找到解決方案。始終getLocationFromName返回空值

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

} 

回答

0

@Dharma

更換

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

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

無需進行初始化。 getFromLocationName無法解決它有一些問題。 –

+0

試試這個會工作 – hArsh

+0

它不工作我試過了... –