Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 217
David Medenjak Avatar asked Nov 07 '22 06:11

David Medenjak


1 Answers

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.

like image 187
zhangxaochen Avatar answered Nov 14 '22 22:11

zhangxaochen