I am trying to get address from current latitude and longitude,but my List getting nothing it always shows empty/null. this is my javacode :
public void onConnected(Bundle bundle) {
Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (location == null) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, (LocationListener) this);
} else {
//If everything went fine lets get latitude and longitude
double currentLatitude = location.getLatitude();
double currentLongitude = location.getLongitude();
Toast.makeText(this, currentLatitude + " WORKS " + currentLongitude + "", Toast.LENGTH_LONG).show();
}
geocoder = new Geocoder(MainActivity.this, Locale.getDefault());
try {
yourAddresses= geocoder.getFromLocation(currentLatitude,currentLongitude, 1);
if (yourAddresses.size() > 0)
{
//String yourAddress = yourAddresses.get(0).getAddressLine(0);
String yourCity = yourAddresses.get(0).getAddressLine(1);
//String yourCountry = yourAddresses.get(0).getAddressLine(2);
TextView city = (TextView)findViewById(R.id.cityname);
city.setText(" "+yourCity);
Toast.makeText(this," "+ yourCity,Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this,""+e,Toast.LENGTH_LONG).show();
}
}
I am getting current latitude and longitude but not address belongs to respective latitude and longitude.