Geocoder.getFromLocation grpc failed on Android real device

前端 未结 9 620
故里飘歌
故里飘歌 2020-12-14 17:14

I need to get the city and state from latitude and longitude. Geocoder does this function to get the city and state. But I am getting an error java.io.IOException: grp

相关标签:
9条回答
  • 2020-12-14 17:42

    It looks like this is ongoing issue that was reported in the Google issue tracker both for real devices and emulators. You can refer to the following bugs:

    https://issuetracker.google.com/issues/64418751

    https://issuetracker.google.com/issues/64247769

    Unfortunately, Google haven't solved these issues yet.

    As a workaround you can consider using the Geocoding API web service. Please note that there is a Java client library for web services that you can find on Github:

    https://github.com/googlemaps/google-maps-services-java

    Using Java client library for web services you can implement reverse geocoding lookup that shouldn't give you the error that you experience with native Android geocoder.

    The Javadoc for client library is located at

    https://googlemaps.github.io/google-maps-services-java/v0.2.5/javadoc/

    I hope this helps!

    0 讨论(0)
  • 2020-12-14 17:42

    When I run with emulator I got the same problem. The problem has solved after i run with real device.

    0 讨论(0)
  • 2020-12-14 17:46

    Making the call to fetch an address via geocoder is recommended to do via an IntentService....but if you're in rapid development mode and don't want to bother setting up a service just yet, you can use a try/catch block

    example in Kotlin:

    try{
     val addressList = geocoder.getFromLocationName(locationName, 3)
     
     //...
    
    }catch(e: IOException) {
    
     when{
      e.message == "grpc failed" -> {/* display a Toast or Snackbar instead*/ }
      else -> throw e
     }
    
    }
    
    
    0 讨论(0)
  • 2020-12-14 17:49

    Check your internet connection . what is going on is at some point between the search and the results rendering , the connection is either to slow or not working at all . so the default error is no GRCP found. your code needs to handle this type of errors and prevent the crash of the map

    0 讨论(0)
  • 2020-12-14 17:49

    It is a reported bug in Android, check @xomena answer for the link.

    Alternately, you can use the web services. Add this to gradle dependencies:

    api 'com.google.maps:google-maps-services:0.10.2'
    

    Sample code to get addresses:

            val geoApiCtx = GeoApiContext.Builder()
                .apiKey(Util.readGoogleApiKey(ctx))
                .build()
    
            val addresses = GeocodingApi.reverseGeocode(geoApiCtx, loc).await()
    
    0 讨论(0)
  • 2020-12-14 17:51

    For me, it was the device time. I was doing some tests, and I had to change the device time. The device time must be set correctly, otherwise you get this error.

    0 讨论(0)
提交回复
热议问题