Geocoder在isPresent()上返回false

时间:2018-04-24 08:14:15

标签: java android android-emulator android-studio-3.0 geocoder

所以我在我的应用程序中为地图编写了一些代码,它在我的手机上工作得很好,遗憾的是它在我的模拟器上不起作用,这对我来说不够舒服这里是代码:

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

所以当我调试它时,我看到了变量&#34; a&#34;在我的模拟器上总是假的。

我使用Android模拟器用于visual studio,因为我有一个AMD处理器(Ryzen 7 1800x),我在其上安装了谷歌游戏商店和谷歌播放服务(地图工作正常,只是地理编码器没有),现在在那里某种方法来解决它?

我在阅读https://developer.android.com/reference/android/location/Geocoder.html时 网站&#34;如果平台中没有后端服务,Geocoder查询方法将返回一个空列表。&#34;我可以以某种方式获得服务吗?在我的模拟器或类似的东西上下载它?

1 个答案:

答案 0 :(得分:0)

首先,isPresent()是一个静态方法,所以调用应该是

Geocoder.isPresent();

IsPresent方法“如果实现了Geocoder方法getFromLocation和getFromLocationName,则返回true”,否则返回false。某些仿真器没有安装地理编码器服务。是方法

geocoder.getFromLocationName 

返回你需要的或一个空数组?

您的代码段在我的Nexus 6P Android 7.0 API 24仿真器上运行正常。