I want to search with a user input text via Android`s GeoCoder class. Here is my code:
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;
}
}
The bounding box I pass to the getFromLocationName roughly represents the german state Bayern. I know that this bounding box doesn´t guarantee that the result address is really there. I found some problems especially when searching via ZIP Code.
- Some result addresses returned when searching by zip code don´t have a "admin area", hence I can´t filter for my desired state (="Bayern").
- Oddly enough if I search for the zip codes 97070, 97078 or 97076, the GeoCoder only returns addresses in Oregon, USA. However these zip codes are also places in the german town of Würzburg. E.g. 97082 will return Würzburg Address, however 97070 (Würzburg central) will not be found, it only returns Oregon addresses.