I have the below code, it works perfectly on some devices and in others the function getFromLocationName return a list with size 0.
For example, in Nexus 6p
it returns the correct result
and in Meizu MX5
it returns a list with size 0.
I have the same permissions and GPS enable for both devices.
Android version on the Nexus 6p
is 7.1.2 and on Meizu MX5
is 5.1
Geocoder geocoder = new Geocoder(context);
List<Address> addresses = geocoder.getFromLocationName(place, 3);
Notes:
- place is the location the user entered (String).
- Geocoder is from android.location.Geocoder;
So why the difference? Is it related to the Android version on the devices?
Geocoder in Android is really don't have the same behaviour on all devices. I have tested the Geocoder with the following devices:
All the devices returning the list but Xiaomi, it returns zero lists. So, we can't depend on Geocoder. The solution is to create our own Geocoder implementation using Google Geocoding API and use it whenever the list returns 0.
Here the implementation of Geocoder (I found it from SO, but can't remember the source) which can be used exatly like using the Geocoder:
Be aware of the daily quota which didn't happen in Android Geocoder API.