Reputation: 8981
I've put together this little function in my android app:
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);
}
The function call goes like this
toAddress(location.getLatitude(), location.getLongitude(), 10);
But the app doesn't display any Toast with the address? I've debugged it and the correct address is in the addresses-list. As you can see I've tried to convert it to a string with the toString()-function. Anybody? Thanks in advance!
Upvotes: 0
Views: 632
Reputation: 6376
Try:
Toast.makeText(getApplicationContext(), address, Toast.LENGTH_LONG ).show();
You are not calling .show() after you create the Toast.
Upvotes: 1