0

So I wrote some code for maps in my app, and it works on my phone just fine, sadly it does not work on my emulator which is not comfortable enough for me here is the code:

String  searchString = mSearchText.getText().toString();

Geocoder geocoder = new Geocoder(this);
List<Address> list = new ArrayList<>();
try{
    int i=0;
    while(list.size()==0 && i<10) {
        boolean a = geocoder.isPresent();
        list = geocoder.getFromLocationName(searchString,1);
        i++;
    }
}catch(IOException e){
    Log.d(TAG, "geoLocate: IOException " + e.getMessage());
}

So when I debug it I see that variable "a" is always false on my emulator.

I use android emulator for visual studio since I have an AMD processor (Ryzen 7 1800x) on which I installed google play store and google play services(map works just fine, just geocoder doesn't), now is there some way to fix it?

As I read on https://developer.android.com/reference/android/location/Geocoder.html website "The Geocoder query methods will return an empty list if there no backend service in the platform." Can I get the service somehow? Download it on my emulator or something like this?

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96

1 Answers1

0

First, isPresent() is a static method so the call should be

Geocoder.isPresent();

IsPresent method "Returns true if the Geocoder methods getFromLocation and getFromLocationName are implemented" and false otherwise. Some emulators don't have the geocoder service installed. Is the method

geocoder.getFromLocationName 

returning what you need or an empty array?

Your snippet works just fine on my Nexus 6P Android 7.0 API 24 emulator.

Alexandru Sandu
  • 314
  • 2
  • 13
  • Returning nothing, array is always empty, works on my Phone when im usb debugging, i this emulator https://imgur.com/PtlR4cG – Aravae Aravae Apr 24 '18 at 08:59
  • And thats what i get from debugger https://imgur.com/lsRiyl1 Visual studio emulator doesnt provide images past API 23 Sadly – Aravae Aravae Apr 24 '18 at 09:07
  • As the documentation says the empty array is because the service does not exist on that emulator. What ide do you use? – Alexandru Sandu Apr 24 '18 at 09:15
  • I belive i tagged i use Anroid Studio 3.0.1. Yes I know it does not exist thats why i asked if i get get it somehow download or sth idk. – Aravae Aravae Apr 24 '18 at 09:20
  • Sorry, i missed that. The only way i see right now is try to use a different emulator, for instance try to use an emulator from android studio. If you need to use the visual studio emulator then for now i have nothing, sorry. – Alexandru Sandu Apr 24 '18 at 09:28
  • Android studio emulator on AMD processor opens 10 minutes so i cant use it but thanks for trying. I've been trying genymotion but had some problems with network adapters :( – Aravae Aravae Apr 24 '18 at 09:34