0
我已經把這個小功能在我的Android應用:地理編碼的Android - 基於座標查找地址
protected void toAddress(double lat, double lng, int maxResults) {
String address = null;
Geocoder gcd = new Geocoder(TarsActivity.this, Locale.getDefault());
List<Address> addresses = null;
try {
addresses = gcd.getFromLocation(lat, lng, maxResults);
} catch (IOException e) {
e.printStackTrace();
}
if (addresses.size() > 0) {
address = addresses.get(0).getLocality().toString();
Toast.makeText(getApplicationContext(), address, Toast.LENGTH_LONG);
}
else
Toast.makeText(getApplicationContext(), "ERROR", Toast.LENGTH_LONG);
}
函數調用是這樣的
toAddress(location.getLatitude(), location.getLongitude(), 10);
但應用程序不用地址顯示任何Toast?我已經調試過它,正確的地址在地址列表中。正如你所看到的,我試圖用toString()函數將它轉換爲一個字符串。任何人?提前致謝!