我第一次使用android.location.Geocoder。想法是:我有一個按鈕,它從EditText獲取輸入並解析位置。到目前爲止它是調試階段,所以我沒有處理程序從線程中獲取消息,只進行地理編碼並寫入logcat。 問:爲什麼這個方法總是返回一個Address對象的空列表?爲什麼Geocoder.getFromLocationName(...)返回一個空列表?
private View.OnClickListener checkLocation = new View.OnClickListener() {
@Override
public void onClick(View v) {
location = ((EditText)findViewById(R.id.getLocation)).getText().toString();
Thread thr = new Thread(){
public void run(){
Log.d("Looking for", location);
Geocoder gc = new Geocoder(ctx,Locale.ITALY);
try {
fa= gc.getFromLocationName(location, 3);
if (fa.isEmpty())Log.d("getFromLocationName", "NothingFound");
else
{
int size= fa.size();
for (int i = 0; i<size ;i++)
Log.d("getFromLocationName.at("+ String.valueOf(i) +")", fa.get(i).getAddressLine(0)+", "+fa.get(0).getAddressLine(1));
}
} catch (IOException e) {
Log.e("IOException", e.getMessage());
}
}
};
thr.start();
}
};
清單:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
有人知道這是爲什麼? (順便說一句,我使用1.6 sdk)輸入嘗試
感謝隊友,這也解決了我的問題! – dgraziotin 2010-05-19 16:04:30