java.io.IOException: grpc failed

前端 未结 24 1042
野性不改
野性不改 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:37

    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 upto 3 decimal places. complete code

            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
    addresses = geocoder.getFromLocation(lat,lon, 1); String cityName = addresses.get(0).getLocality();

提交回复
热议问题