简体   繁体   English

Geocoder在isPresent()上返回false

[英]Geocoder returns false on isPresent()

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. 因此,当我调试它时,我在模拟器上看到变量“ a”始终为假。

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? 我使用Visual Studio的Android模拟器,因为我有一个AMD处理器(Ryzen 7 1800x),上面安装了Google Play商店和Google Play服务(地图工作正常,只是地理编码器无法工作),现在可以通过某种方式对其进行修复?

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." 正如我在https://developer.android.com/reference/android/location/Geocoder.html网站上阅读的那样 “如果平台中没有后端服务,则Geocoder查询方法将返回一个空列表。” Can I get the service somehow? 我能以某种方式获得服务吗? Download it on my emulator or something like this? 可以在我的模拟器上下载它吗?

First, isPresent() is a static method so the call should be 首先,isPresent()是静态方法,因此调用应为

Geocoder.isPresent();

IsPresent method "Returns true if the Geocoder methods getFromLocation and getFromLocationName are implemented" and false otherwise. IsPresent方法“如果实现了Geocoder方法getFromLocation和getFromLocationName,则返回true”,否则返回false。 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. 您的代码段可以在Nexus 6P Android 7.0 API 24仿真器上正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM