I know sometimes google back-end service might not be available.
Hence a solution might be to loop until i get the data.
private class getLocationDetails extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
Log.d("looping", "" + count + "");
count++;
double lat = Double.parseDouble(params[0]);
double lng = Double.parseDouble(params[1]);
List<Address> addresses = null;
try {
Geocoder gCoder = new Geocoder(ImageAndLocationActivity.this,
Locale.getDefault());
addresses = gCoder.getFromLocation(lat, lng, 1);
Address addr = addresses.get(0);
user_country = addr.getCountryName();
user_city = addr.getLocality();
user_district = addr.getSubAdminArea();
if (user_city == null) {
user_city = user_district;
}
} catch (Exception e) {
Log.e("Exception in getLocationDetails - ", e.getMessage());
return null;
}
return "";
}
@Override
protected void onPostExecute(String result) {
if (result != null) {
Log.d("user_city = ", "" + user_city);
} else {
new getLocationDetails().execute(CurrentLat + "", CurrentLng
+ "");
}
}
@Override
protected void onPreExecute() {
}
@Override
protected void onProgressUpdate(Void... values) {
}
}
But i am not able to get the location at all:
LogCat:
02-27 16:29:49.568: D/looping(10966): 110355
02-27 16:29:49.568: E/Exception in getLocationDetails -(10966): Service not Available
02-27 16:29:49.573: D/looping(10966): 110356
02-27 16:29:49.573: E/Exception in getLocationDetails -(10966): Service not Available
02-27 16:29:49.573: D/looping(10966): 110357
02-27 16:29:49.573: E/Exception in getLocationDetails -(10966): Service not Available
and ofcourse i have added all the needed permissions:
<uses-permission android:name="android.permission.INTERNET" />
I am trying this on Samsung Galaxy Note GT-N7000 (4.0.4 version)
Am i missing any settings? related to device or application ? Or this usually happens? If so any better solution to resolve this??
Thank You
Restart the device and it will fix the issue.
use this trick.
simply edit the project.properties
The reason is that the Geocoder class is present in the core Android framework, but depends on code contributed by the Google APIs to function properly. Even if your AVD includes the Google APIs, your project still needs to be built against that specific build target.
I'm using the code that is up (direct access to Google Maps) "merged" with Geocoder code, as shown below (Pay special attention to "try catch"):
This worked excellent for me because when Geocoder not work, i use direct access to Google Maps.
Cheers!
Service not Available - Geocoder Android when i get this error in some cooked roms i wrote this library i hope could be useful. https://github.com/dnocode/gapis
I have also had trouble with this error. It happened when I updated my device to Marshmallow recently.
If I reboot, it works once, but then will fail, and not work at all thereafter.
I created an AsyncTask like other people, that only returns the address from the first result of the json response.
To use the code below, call it constructed with your api key, and you use a Location object as input to execute the AsyncTask. You can import Location with the following.
import android.location.Location;
You will have to get the current Location with the LocationManager, by requesting an update to it.Make sure you replace the api key with your own, and also make sure you enable it in the google cloud console. That is where you manage all the google apis for your particular project.
Copy this class as an Inner Class in the Activity that you are needing the reverse geocoded address.
Workaround using direct access to google maps: