6

In my android app i am trying to get the address from lat lng using the Geocoder using getFromLocation method and the GeocodeListener but sometimes the app is getting crashed

Crash Log

Caused by java.io.IOException: egma: DEADLINE_EXCEEDED: Deadline CallOptions will be exceeded in 4.959774531s. 
       at android.location.Geocoder$GeocodeListener.getResults(Geocoder.java:246)
       at android.location.Geocoder.getFromLocation(Geocoder.java:134)

Code

geocoder.getFromLocation(
  latLng.latitude,
  latLng.longitude,
  1,
  object : Geocoder.GeocodeListener {
            override fun onGeocode(addresses: MutableList<Address>) {
              val addressLine = addresses.first().getAddressLine(0)
                   onAddressResult(addressLine, null) // callback
             }

             override fun onError(errorMessage: String?) {
               super.onError(errorMessage)
                  onAddressResult(null, errorMessage)
             }
  },
)

What is the reason for the crash. how can i avoid it?

Chandra Shekhar
  • 3,550
  • 2
  • 14
  • 22

1 Answers1

-1

Have you tried using try/catch block it might help to catch and bypass exception

  • 1
    problem is not to bypass exception. the callback listener has to resolve at some point of time in future. if getting the address is a mandatory, bypassing it is not the solution. – Chandra Shekhar Mar 04 '23 at 04:41