Geocoder.getFromLocation grpc failed on Android real device - android

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: grpc failed in below line only on Android real device. It is working fine in emulators.
new Geocoder(context).getFromLocation(latLng.latitude, latLng.longitude, 1).get(0);
Also I have been calling this function using Asynctask which is suggested in another post Geocoder grpc failed in stack overflow but nothing works for me.
And I have restart the device as well but still it is failing.
Help needed here. Thanks in advance.
Note: I tested in Google Pixel XL, Samsung S6 edge, Samsung S4.

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!

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

Happened for me both with a real and an emulated device. Solved my restarting the app after cleaning the project

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.

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()

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

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
}
}

What I did was, I changed my accuracy to GPS only, in this case, the application was not calculating my location. I again changed the accuracy to high accuracy and the application started working, no crash at all. you can change your GPS accuracy from location setting on your android mobile.

Using an emulator. I had to update the Google Play Services on the device and then it worked!

Related

Geocoder getFromLocation failed

I'm trying to get placemarks from coordinates.
I'm using geoLocator for that. It was working fine today morning, but now, it throws platform exception.
PlatformException(IO_ERROR, A network error occurred trying to lookup the supplied coordinates (latitude: <lat>, longitude: <long>)., null)
It says it's a network error, but my device is connected to the internet,
First, i thought there might be some problem in the Geolocator package, so i used Geocoding package, but the problem persists.
This is the error from geocoder.
Geocoder getFromLocation --- mService = android.location.ILocationManager$Stub$Proxy#e8c2197, ex = grpc failed, return results = []
Please help.
Try to WIPE DATA on your emulator.
Restart it.
It works.
See this flutter_geocoding issue (closed): https://github.com/Baseflow/flutter-geocoding/issues/23
Two solutions presented:
create a new emulator
stop WiFi on the emulator, restart WiFi and let it find the network (AndroidWiFi)
Solution 2 worked for me.
try to add localeIdentifier parameter. works for me. my function code will be like
List<Placemark> newPlace = await GeocodingPlatform.instance.placemarkFromCoordinates(position.latitude, position.longitude,localeIdentifier: "en");
I had the same problem.
Try another emulator (create another emulator as if you are using another android or ios device).
May be the current device that is being emulated is having problems connecting to the internet
its mainly due to change in location of your device if you're using a external device like an android phone then you should reboot your device and it'll work .
I've faced the same issue.
Reason - The internet was not working inside my emulator.
Answer - If internet is not working inside your emulator, cold wipe your emulator from the virtual device manager and check again.
It solved my issue.
Not sure what is the problem, but I ended up making a new android emulator(a new emulated device) and it worked fine.

Reverse Geocode a lat/long coordinate using Geocoder on a HMS device

I'm trying to geocode a lat/long coordinate using the android.location.Geocoder on a HMS (Huawei Mobile Services) device, but I keep getting an empty list as the result.
val result = geoCoder.getFromLocation(latitude, longitude, MAX_RESULTS) // [] on HMS
To verify that this in fact should work I checked Geocoder.isPresent() which returns true.
Looking at the LogCat output I can see the following lines which suggest that I am missing some API key or didn't configure something correctly...
XX/? I/HwGeoCoderProvider: [I/HwLocation/HwGeoCoderProvider 1877:388 HwGeoCoderProvider.java:136] onGetFromLocation: start to GetFromLocation
XX/? D/HwGeoCoderProvider: [D/HwLocation/HwGeoCoderProvider 1877:388 HwGeoCoderProvider.java:434] exceed max requesting limit
XX/? D/HwGeoCoderProvider: [D/HwLocation/HwGeoCoderProvider 1877:388 HwGeoCoderProvider.java:162] exceed max requesting limit
XX/? I/HwGeoCoderProvider: [I/HwLocation/HwGeoCoderProvider 1877:388 HwGeoCoderProvider.java:455] {callTime=..., service=hwLocation, rom_type=1001, transId={{some uuid}}, package=com.android.phone, apiName=GeoCode_getFromLocation, costTime=1, result=10400}
I tried this on a P40 Pro, which has the latest HMS Core version (5.0.0.304) installed. I have received a few results before, so it definitely does work, but then it apparently hits this limit and stops working.
How can I geocode a lat/long using android.location.Geocoder on a HMS device? What configuration / setup is necessary to avoid hitting this limit?
I've seen workarounds mentioned to use the location/site kit instead, but I'd prefer to use the "vanilla" Android API if possible.
Your question is that when using the native Android API getFromLocation on an HMS device, the system prompts that the API call times exceed max requesting limit.
The possible cause is that you frequently initiated requests when the network condition was poor. To ensure proper use of resources, the system has limited the resource usage. You are advised to restart HMS Core (APK) or the device, and initiate requests when the network condition is good, as well as ensure that no more than 10 requests are initiated in a short period of time.
Thanks for your feedback. This issue will be rectified in Location Kit 5.0.2, which will be released on September 15, 2020.
Update:
The new version of Location Kit 5.0.2.301 is here, modified the description of the setMaxWaitTime method in the LocationRequest class, preventing slow first location callback due to incorrect settings.

IndexOutOfRangeExeption Xamarin Live Player

I'm studying Xamarin for two weeks now and I'm following the Xamarin.University course (Consuming REST-based Web Services (XAM150)). In an exercise we have to simply check the connection of the phone. My emulator (Android 7.0) in Visual Studio 2017 does it very well. But when I try on my actual phone (Android 7.1) using Xamarin Live Player, the app will not start and the following Error appears on my phone:
"Visualization Error. Index was outside the bounds of the array.
(IndexOutOfRangeExeption)"
I've searched Google and the forum of Xamarin.University but no luck, it seems that no one else has this problem. When I debug, it stops at when it checks the connectivity. I use the Xam.Plugin.Connectivity for asking the connection and yes, it is referenced in all the parts of the project.
I've come from using this code from the site:
using Plugin.Connectivity;
public App() {
// The root page of your application
MainPage = CrossConnectivity.Current.IsConnected
? (Page) new NetworkViewPage()
: new NoNetworkPage();
}
To this to debug:
using Plugin.Connectivity;
public App() {
InitializeComponent();
try {
var isConnected = CrossConnectivity.Current.IsConnected;
MainPage = isConnected
? (Page)new NetworkViewPage()
: (Page)new NoNetworkPage();
} catch (Exception e) {
throw e;
}
//MainPage = new NetworkViewPage();
}
All this code works for my emulator, but not for my phone. I can display the different pages on my phone but not when I check for the connectivity so the error is really from the plugin and not from my pages.
Has someone any idea what I can try to make this work?
Frauke Nonnenmacher pointed out that it could be a problem with Xamarin Live Player and apparantly that is the issue. If I implement it on my phone with USB debugging, it works just fine. It didn't occur to me that Live Player could be the issue since Xamarin.University wants you to use it and I didn't find anybody on the forum there that had the same problem.
My guess is that checking the connection gives a problem with Xamarin Live Player because it works over the network, you can't use the Player if you don't have a wifi connection. So maybe something goes wrong there.
It is still a mystery why it doesn't work, but a workaround is just USB debugging.

How to get enabled print Services in Android 7.0

I am trying to get the enabled print services in Android.
Below code works fine in upto Android 6.0. But it is not working in Android 7.0
String enabledPrintServices = Settings.Secure.getString(mContext.getContentResolver(), "enabled_print_services");
In Nougat and up, for some reason you have to use "disabled_print_services" instead of "enabled_print_services" to get a list of disabled print services.
Documentation in source code is here.
If all you need is to see if your print service is enabled or disabled, then this alternative would be equally effective. Otherwise, if your wish is to list all enabled print services, then I have not found any such code that works for Android 7.0 and up.

Geocoder in android gives "Service not available error" sometimes on some device. How to deal with this?

Geocoder in android gives "Service not available error" sometimes on some device. How to deal with this? This error occurs in pre M devices only.
P.S I know this question has been asked many times but i didnot got the ultimate solution for same.
The actual reason why Geocoder was not working is because the NetworkLocator was killed in action. Probably due to less memory or maybe you used the Task Manager to kill all services.
This error occurs occasionally if the GeoCoding provider fails and is unable to geocode your location.
So to solve this you have to restart the device.

Categories

Resources