I managed to get the city name using the GeoCoder, but sometimes the GPS returns values that GetLocality can not recognize (returning "null"). I think the best solution is to get the nearest city name. Can anyone tell me please how to do that. Or if there is another alternative to solve it, it's OK.
public void getCityName(double dLatitude, double dLongitude) throws IOException{
Geocoder gcd = new Geocoder(this, Locale.getDefault());
List<Address> addresses = gcd.getFromLocation(dLatitude, dLongitude, 1);
TextView cityname = (TextView)findViewById(R.id.city_name);
if (addresses.size() > 0) {
cityname.setText( "" +addresses.get(0).getLocality() + "," + addresses.get(0).getCountryName() );
}
}