When I use call getFromLocationName I get an IOException with description \"grpc failed\".
Code that\'s ran
@Override
public void onMapReady(GoogleMa
I think this depends on the location of the device. because google map sometimes not working properly in some area. I'm from Iran and I also had this problem on real device and emulator. After a while go with this problem, I used a vpn application and it worked on the real device and emulator. because vpn application changed my ip address.
This issue has already been reported, you can find other stack posts talking about it. Here is a comment on google issue with some of the different way geocoder crashes. I advise you to surround your part of code with try and catch, so your application doesn't stop.
In my case I just turned on (permission granted) the Position from app permission setting.
From my experience, I can say this error is thrown by the Geocoder
's getFromLocation()
method. So don't do the following:
IOExeption
will be thrown. Again, anything depending on the result of this method will crash. Handle this case.This worked for me.
SomeTimes Geocoder failed when latitude and longitude contain above 3 decimal places, or it may be said that Geocoder can not decode every latitude and longitude. you need to limit latitude and longitude up to 3 decimal places.
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(3);
double lat = Double.parseDouble(df.format(currentUserLocation.latitude));
double lon = Double.parseDouble(df.format(currentUserLocation.longitude));
Geocoder geocoder = new Geocoder(myContext, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(lat,lon, 1);
String cityName = addresses.get(0).getLocality();
Source : https://github.com/xamarin/Essentials/issues/759#issuecomment-621270050
UPDATE:
The problem seems to be solved now. I'm not sure if it the problem ever was on my end, so if you had this problem prior to this post, re-run your app and see if it works now.
If it still doesn't work, here is the stuff I did myself that "might" have made it work: