我正在尝试添加Twitter样式添加位置以供Feed。 当我尝试搜索城市时,例如以" new york"结果与纽约作为图像有许多不同的结果
我的地理编码如下
public static List<String> getAddressesFromLocation(Context context, double lat, double lon) {
Locale current = context.getResources().getConfiguration().locale;
Geocoder coder = new Geocoder(context, current);
List<Address> addresses;
int maxResult = 5;
List<String> addressList = new ArrayList<String>();
try {
// May throw an IOException
addresses = coder.getFromLocation(lat, lon, maxResult);
if (addresses == null) {
return null;
}
for (int j = 0; j < addresses.size(); j++) {
Address returnedAddress = addresses.get(j);
String city = (returnedAddress.getLocality() == null || returnedAddress.getLocality().isEmpty()) ? "" : (returnedAddress.getLocality() + ", ");
String state = (returnedAddress.getAdminArea() == null || returnedAddress.getAdminArea().isEmpty()) ? "" : (returnedAddress.getAdminArea() + ", ");
String country = (returnedAddress.getCountryName() == null || returnedAddress.getCountryName().isEmpty()) ? "" : returnedAddress.getCountryName();
if((city == null || city.isEmpty()) && (state == null || state.isEmpty())){
continue;
}
if(city.equals(state)){
state = "";
}
addressList.add(city + state + country);
}
} catch (IOException ex) {
ex.printStackTrace();
}
return addressList;
}
一切正常,但结果不对。有什么问题?