The Problem which was causing: Geocoding need a connection to Google Api's. On Genymotion I didn't had till I installed 'Gapps'.
The Solution: e.g Install Gapps on Genymotion
I wan't to get the Location informations from longtitude
and latitude
. In my other app this function works great but in my other projects it didn't working at all.
Do it requires a google json file for it? A key? A whatever ?
I didn't find a solution yet. I really don't know why it returns everytime null. I tried with several locations.
private String getLocationFromLongLati(String longi, String lati) throws IOException {
if (ActivityCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 1001);
} else {
Geocoder geocoder = new Geocoder(MainActivity.this, Locale.GERMAN);
List<Address> nm = geocoder.getFromLocation(Double.valueOf(lati), Double.valueOf(longi), 1);
if(nm != null && nm.size()>0) {
return nm.get(0).getPostalCode() + ", " + nm.get(0).getLocality();
}
}
return null;
}