0

I have a call to the Android Geocoder function getFromLocation it used to work most of the times before June, 6, 2019. But after that it fails a lot.

I used to have less than 10 errors before that day, then on the 6th it spiked to a 100 and it's been around 80 a day since then.

That's what happened, and there weren't any new version or code change around these days. The exception have a message that only says "GPRC Failed"

Error occurrence graphic

My code is pretty standard:

try {
    addresses = V1Motorista.getGeocoder().getFromLocation(lastLocation.latitude, lastLocation.longitude, 5)
} catch (e: Exception) {
    Log.d("GEOCODE TRY 1", e.message)
    Analytics.logError("Erro ao tentar resolver Geocode pela primeira vez", e)
}

and

class V1Motorista : Application() {

    companion object {
        lateinit var instance: V1Motorista

        fun getGeocoder(): Geocoder {
            return Geocoder(instance)
        }

    }
...
}

I don't really now what changed, any help appreciated.

Pedro Malta
  • 198
  • 9

2 Answers2

0

Try this out, hope it will work

public String getAddress(double lat, double lng) {
        Geocoder geocoder = new Geocoder(context, Locale.getDefault());
        try {
            List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
            if (addresses.size() > 0) {
                Address obj = addresses.get(0);
                String mainAddress = obj.getAddressLine(0);
                String add = obj.getAddressLine(0);
                add = add + "\n" + obj.getCountryName();
                add = add + "\n" + obj.getCountryCode();
                add = add + "\n" + obj.getAdminArea();
                add = add + "\n" + obj.getPostalCode();
                add = add + "\n" + obj.getSubAdminArea();
                add = add + "\n" + obj.getLocality();
                add = add + "\n" + obj.getSubThoroughfare();
                Log.e("IGA", "Address" + add);
                return mainAddress;
            } else {
                Toast.makeText(context, "Address still not selected.", Toast.LENGTH_SHORT).show();
                return "";
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
            return null;
        }
    }
Mohimenul Joaa
  • 646
  • 6
  • 10
  • That is comparable to what I do. The only real difference is that you pass a Locale at the constructor. But per the Geocoder documentation that is not necessary if you are using the default locale. "Constructs a Geocoder whose responses will be localized for the default system Locale.". – Pedro Malta Jun 18 '19 at 20:41
  • Also, I try 2 times... the second time I try with "1" at the last parameter. Both are failing at the exactly same rate. – Pedro Malta Jun 18 '19 at 20:43
  • This shouldn't be the case. please check your **App signing certificate** and google_maps_key All of your fingerprints need to be present in the google cloud platform google maps credentials. – Mohimenul Joaa Jun 19 '19 at 05:23
  • The App signing is OK, I use GMaps and Directions Web API within the app and they both work ok. I can't find any documentation about the key for using the Geocoder class, there's nothing [here](https://developer.android.com/training/location/display-address), can you help me? – Pedro Malta Jun 21 '19 at 18:23
-1

I had this same problem today in May 2020, The issue came from Google itself, they updated some dependencies, I noticed when I logged into my cloud console. Just add the following to your dependencies: Implementation ‘com.google.android.libraries.places:2.2.0’ or the latest version at the time you’re looking at this. It should work.

Joseph
  • 1