List<Address> addressList = geocoder.getFromLocationName(locationName, 5);
Log.d("size:",""+addressList.size());
size总是打印1。例如:我将街道地址marathahalli作为locationName。我只得到1个值,但当我在谷歌地图上尝试相同的街道地址时,我得到10个地址。
我已经使用了下面的代码,它为我工作,试试这个代码。
String address = etEntreAddress.getText().toString();
Geocoder geocoder = new Geocoder(this, Locale.ENGLISH);
try {
List<Address> addresses = new ArrayList<Address>();
addresses = geocoder.getFromLocationName(
TextUtils.htmlEncode(address), 5);
if (addresses != null) {
for (int j = 0; j < 1; j++) {
Address returnedAddress = addresses.get(j);
Log.i("address", "returnedAddress :" + returnedAddress);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}