java.io.IOException: grpc failed

前端 未结 24 885
野性不改
野性不改 2020-12-02 20:00

When I use call getFromLocationName I get an IOException with description \"grpc failed\".

Code that\'s ran

@Override
public void onMapReady(GoogleMa         


        
相关标签:
24条回答
  • 2020-12-02 20:29

    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.

    0 讨论(0)
  • 2020-12-02 20:30

    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.

    0 讨论(0)
  • 2020-12-02 20:32

    In my case I just turned on (permission granted) the Position from app permission setting.

    0 讨论(0)
  • 2020-12-02 20:33

    From my experience, I can say this error is thrown by the Geocoder's getFromLocation() method. So don't do the following:

    • Do not call this method on main thread. This will freeze the UI and if anything which depends on the result of this method will crash. Handle this case.
    • When there's no internet connection, again, the IOExeption will be thrown. Again, anything depending on the result of this method will crash. Handle this case.
    0 讨论(0)
  • 2020-12-02 20:33

    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

    0 讨论(0)
  • 2020-12-02 20:34

    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:

    1. I uninstalled and deleted all files related to Android Studio. (NOT the project files).
    2. I then reinstalled Android Studio, and reopened the project back up.
    3. When running the app (I'm using Android Studio's built in emulator) I used a different virtual device and device API. This time I ran it on Pixel, with API 23, x86_64.
    0 讨论(0)
提交回复
热议问题