地理编码器在ISPRESENT()上返回false



所以我在应用程序中写了一些代码,它可以在手机上工作,可悲的是,它对我的仿真器不起作用,这对我来说不够舒适,这是代码:

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

因此,当我调试时,我会看到变量" a"在我的仿真器上始终是错误的。

我将Android Emulator用于Visual Studio,因为我有一个AMD处理器(Ryzen 7 1800X(,我在该处理器上安装了Google Play商店和Google Play服务(地图工作正常,Geocoder not(,现在有某种方法修复它?

当我在https://developer.android.com/reference/android/location/location/geocoder.html上阅读时网站"如果平台中没有后端服务,地理编码器查询方法将返回一个空列表。"我可以以某种方式获得服务吗?在我的仿真器上下载它?

首先,ispresent((是静态方法,因此调用应为

Geocoder.isPresent();

ISPRESENT方法"如果实现了GETFromlocation和GetFromlocationname,则返回true",否则为false。一些模拟器没有安装地理编码器服务。是方法

geocoder.getFromLocationName 

返回您需要的东西或一个空数组?

您的摘要在我的Nexus 6P Android 7.0 API 24模拟器上正常工作。

最新更新