为什么地理coder.getFromLocationName(...)返回一个空列表? [英] why Geocoder.getFromLocationName(...) returns an empty list?
问题描述
我使用首次android.location.Geo $ C $铬。的理念是:我有一个监听器上的按钮,这需要从一个EditText输入和解决的位置。到现在为止它的调试阶段,所以我没有处理从线程,只有地理编码和写入的logcat服用消息。
问:为什么这个方法总是返回地址对象的空列表
I'm using the android.location.Geocoder for the first time. The Idea is: I have a Listener on a button which takes input from an EditText and resolve the location. Up to now it's debugging phase, so I have no handler taking messages from the thread, only geocoding and write to logcat. Q: Why this method always returns an empty list of Address objects?
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)输入尝试
Somebody knows why? (btw I am using 1.6 sdk) Input tried
推荐答案
该项目并非针对正确的AVD。要使用你的地理位置,使它指向实现谷歌的API的AVD。有一次,我改变了这一切工作就好了。对不起,打扰
the project wasn't targeting the correct AVD. To use geolocation you have to make it point an avd implementing the google APIs. Once I changed it everything worked just fine. Sorry for bothering
这篇关于为什么地理coder.getFromLocationName(...)返回一个空列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!