为什么 Geocoder.getFromLocationName(...) 返回一个空列表?
我是第一次使用 android.location.Geocoder。想法是:我在按钮上有一个侦听器,它从 EditText 获取输入并解析位置。到目前为止,它处于调试阶段,所以我没有处理程序从线程获取消息,只有地理编码并写入 logcat。 问:为什么这个方法总是返回一个空的 Address 对象列表?
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)输入尝试过
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();
}
};
manifest:
<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" />
Somebody knows why? (btw I am using 1.6 sdk) Input tried
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该项目没有针对正确的 AVD。要使用地理定位,您必须使其指向实现 google 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
因为它无法识别您输入的地址或者无法访问该服务。
你输入什么地址?尝试一些简单的内容,例如邮政编码、城市或州名称。
Because it doesn't recognize the address you are putting in or it can't reach the service.
What address are you putting in? Try something as simple as a zip code or city or state name.