【发布时间】:2017-08-11 09:32:21
【问题描述】:
我想通过 Android 的 GeoCoder 类使用用户输入文本进行搜索。这是我的代码:
Geocoder iGeocoder = new Geocoder(getContext(), Locale.GERMAN);
public Address getAdress(String aUserInput) {
List<Address> tAddressList = iGeocoder.getFromLocationName(aUserInput, 1000, 47.060940, 8.564278, 51.526396, 13.736392);
if(tAddressList != null &&
tAddressList.size() > 0) {
for(Address tAddress : tAddressList) {
// return the first adress found for germany.
Log.e(TAG, "returning Adress: " + tAddress );
if(tAddress.getCountryCode().equals("DE")) {
return tAddress;
}
}
return null;
} else {
return null;
}
}
我传递给getFromLocationName 的边界框大致代表了德国拜仁。我知道这个边界框并不能保证结果地址确实存在。我发现了一些问题,尤其是在通过邮政编码搜索时。
- 按邮政编码搜索时返回的某些结果地址没有“管理区域”,因此我无法筛选出我想要的状态 (="Bayern")。
- 奇怪的是,如果我搜索邮政编码 97070、97078 或 97076,GeoCoder 只返回美国俄勒冈州的地址。然而,这些邮政编码也位于德国维尔茨堡镇。例如。 97082 将返回 Würzburg 地址,但找不到 97070(Würzburg 中心),它只返回俄勒冈州地址。
【问题讨论】:
-
就是代码。这一切都在一行“getFromLocationName..”中完成。你错过了什么吗?
-
结果数(1000)和边界坐标是静态的,“aUserInput”是用户正在搜索的内容,它可以是从邮政编码到城市或街道名称甚至兴趣点的任何内容.
-
非常感谢您的宝贵时间!
-
你刚刚打错字了。在下面查看我的答案
-
@YvetteColomb 试图最小化错误,因为android developper 说第二个参数是
the desired Locale for the query results。我不认为 OP 使用文档失败了。我猜这是对locale或typo的混淆
标签: java android google-maps